Server Side Programming Articles

Page 791 of 2109

Large Fibonacci Numbers in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 557 Views

To display large Fibonacci numbers in C#, we need to handle numbers that exceed the range of standard integer types. The Fibonacci sequence grows exponentially, so after just 40-50 terms, the values become too large for int or even long data types. For truly large Fibonacci numbers, we use the BigInteger class from System.Numerics, which can handle arbitrarily large integers without overflow. Syntax Following is the basic syntax for generating Fibonacci numbers − int val1 = 0, val2 = 1, val3; for (int i = 2; i < n; i++) { val3 ...

Read More

Lambda Expressions in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 817 Views

A lambda expression in C# is an anonymous function that provides a concise way to write inline functions. Lambda expressions use the => operator, read as "goes to", which separates the input parameters from the expression body. Lambda expressions are commonly used with LINQ methods, event handlers, and delegates to create short, readable code without defining separate methods. Syntax Following is the basic syntax for lambda expressions − (input-parameters) => expression For single parameter, parentheses are optional − x => x * 2 For multiple statements, use curly braces ...

Read More

How to print duplicate characters in a String using C#?

George John
George John
Updated on 17-Mar-2026 5K+ Views

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 More

How to print the first ten Fibonacci numbers using C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 855 Views

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 More

How to print one dimensional array in reverse order?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 613 Views

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 More

How to remove an empty string from a list of empty strings in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 1K+ Views

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 More

How to find a number using Pythagoras Theorem using C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 652 Views

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 More

How to find a number in a string in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 528 Views

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 More

How to find and display the Multiplication Table in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 1K+ Views

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 More

How to find date difference in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 167 Views

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 More
Showing 7901–7910 of 21,090 articles
« Prev 1 789 790 791 792 793 2109 Next »
Advertisements