Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Csharp Articles
Page 116 of 196
How to print duplicate characters in a String using C#?
Finding duplicate characters in a string is a common programming task in C#. A duplicate character is one that appears more than once in the string. We can solve this by counting the frequency of each character and then displaying those with a count greater than 1. Using Character Frequency Array The most efficient approach uses an integer array to store the frequency of each character. Since there are 256 possible ASCII characters, we create an array of size 256 − using System; class Demo { static int maxCHARS = 256; ...
Read MoreHow to print the first ten Fibonacci numbers using C#?
The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, starting from 0 and 1. In C#, we can generate and print the first ten Fibonacci numbers using loops and basic arithmetic operations. Understanding the Fibonacci Sequence The Fibonacci sequence begins with 0 and 1. Each subsequent number is calculated by adding the two previous numbers together − Fibonacci Sequence Pattern 0 1 1 ...
Read MoreHow to print one dimensional array in reverse order?
In C#, there are several ways to print a one-dimensional array in reverse order. You can either reverse the actual array using Array.Reverse() or print the elements in reverse without modifying the original array. Syntax Using Array.Reverse() to reverse the array − Array.Reverse(arrayName); Using a reverse loop to print without modifying the array − for (int i = arr.Length - 1; i >= 0; i--) { Console.WriteLine(arr[i]); } Using Array.Reverse() Method The Array.Reverse() method permanently reverses the order of elements in the array − ...
Read MoreHow to remove an empty string from a list of empty strings in C#?
In C#, you can remove empty strings from a list using several methods. Empty strings can be truly empty ("") or contain only whitespace characters (" "). This article demonstrates different approaches to remove these empty or whitespace-only strings from a list. Syntax Using RemoveAll() method to remove empty strings − list.RemoveAll(string.IsNullOrEmpty); Using RemoveAll() with lambda expression to remove empty and whitespace strings − list.RemoveAll(x => string.IsNullOrWhiteSpace(x)); Using LINQ Where() method to filter out empty strings − var filteredList = list.Where(x => !string.IsNullOrEmpty(x)).ToList(); Using RemoveAll() Method ...
Read MoreHow to find a number using Pythagoras Theorem using C#?
The Pythagorean theorem states that in a right-angled triangle, the square of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the other two sides. In C#, we can use the Math.Sqrt() method to calculate the hypotenuse or find missing sides. Syntax The basic formula for Pythagorean theorem is − c² = a² + b² c = Math.Sqrt(a * a + b * b) Where c is the hypotenuse, and a and b are the other two sides of the right triangle. ...
Read MoreHow to find a number in a string in C#?
To find a number in a string in C#, you can use Regular Expressions (Regex) from the System.Text.RegularExpressions namespace. The Regex pattern \d+ matches one or more consecutive digits in a string. Syntax Following is the syntax for creating a Regex pattern to match numbers − Regex regex = new Regex(@"\d+"); Match match = regex.Match(inputString); Following is the syntax for checking if a match was found − if (match.Success) { string number = match.Value; } Using Regex to Find the First Number The Match method ...
Read MoreHow to find and display the Multiplication Table in C#?
A multiplication table displays the product of a number with a sequence of other numbers. In C#, you can generate and display multiplication tables using loops and formatted output. This is useful for educational applications, mathematical calculations, or creating reference tables. Syntax The basic structure for creating a multiplication table uses a loop with formatted output − while (counter
Read MoreHow to find date difference in C#?
To find the difference between two dates in C#, you can use the DateTime class along with the TimeSpan structure. The DateTime subtraction operation returns a TimeSpan object that represents the time difference between two dates. Syntax Following is the syntax for calculating date difference − DateTime date1 = new DateTime(year, month, day); DateTime date2 = new DateTime(year, month, day); TimeSpan difference = date2 - date1; The TimeSpan object provides various properties to access different units of the difference − difference.Days // Total ...
Read MoreHow to print a blank line in C#?
To print a blank line in C#, you can use several methods. The most common approach is using Console.WriteLine() without any parameters, which outputs an empty line to the console. Syntax Following are the different ways to print a blank line − Console.WriteLine(); // Empty line Console.WriteLine(""); // Empty string Console.WriteLine(" "); // Single space Console.Write(""); // Newline character ...
Read MoreHow to print a BinaryTriangle using C#?
A binary triangle is a pattern formed using alternating 0s and 1s arranged in a triangular shape. Each row contains an increasing number of digits, and the pattern alternates between 0 and 1 for each position across all rows. How It Works The binary triangle is created using nested loops where the outer loop controls the number of rows, and the inner loop prints the alternating 0s and 1s for each row. A toggle variable switches between 0 and 1 to create the alternating pattern − Binary Triangle Pattern 1 ...
Read More