Server Side Programming Articles

Page 795 of 2109

How to find the length of jagged array using a property?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

A jagged array in C# is an array of arrays where each inner array can have different lengths. To find the length of a jagged array, you use the Length property, which returns the number of inner arrays (rows) in the jagged array. Syntax Following is the syntax for declaring a jagged array − dataType[][] arrayName = new dataType[size][]; To get the length of a jagged array, use the Length property − int numberOfRows = arrayName.Length; Jagged Array Structure [0, 0] ...

Read More

C# program to check if two lists have at-least one element common

Samual Sam
Samual Sam
Updated on 17-Mar-2026 1K+ Views

A common requirement in C# programming is to check if two lists share at least one common element. This can be achieved using various approaches, from simple nested loops to more efficient methods using HashSets and LINQ. The most efficient approach is to use HashSet operations or LINQ's Intersect() method, which provide optimal performance for finding common elements between collections. Using HashSet Intersection HashSet provides an Overlaps() method that efficiently checks if two sets have any common elements − using System; using System.Collections.Generic; public class Program { public static void ...

Read More

C# program to check if all the values in a list that are greater than a given value

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 2K+ Views

To check if all values in a list are greater than a given value, you need to iterate through each element and compare it against the threshold. If any element fails the condition, then not all values meet the criteria. There are multiple approaches to solve this problem in C# − using traditional loops, LINQ methods, or built-in array methods. Using Traditional For Loop The most straightforward approach uses a for loop to iterate through the array and check each element − using System; public class Program { public static ...

Read More

C# program to print unique values from a list

Samual Sam
Samual Sam
Updated on 17-Mar-2026 6K+ Views

In C#, you can extract unique values from a List using the Distinct() LINQ method. This method filters out duplicate elements and returns only the unique values, maintaining the order of their first occurrence. Syntax Following is the syntax for using Distinct() method − List uniqueList = originalList.Distinct().ToList(); The Distinct() method returns an IEnumerable, so we use ToList() to convert it back to a List. Using Distinct() with Integer List Here's how to remove duplicate integers from a list and display only unique values − using System; using System.Collections.Generic; using ...

Read More

C# program to remove an item from Set

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

A HashSet in C# is a collection that stores unique elements and provides efficient methods to add, remove, and search items. To remove items from a HashSet, you can use methods like Remove(), RemoveWhere(), or Clear(). Syntax Following are the common methods to remove items from a HashSet − // Remove a specific item bool removed = hashSet.Remove(item); // Remove items based on a condition int count = hashSet.RemoveWhere(predicate); // Remove all items hashSet.Clear(); Using Remove() Method The Remove() method removes a specific item from the HashSet and returns true if ...

Read More

C# program to remove all duplicates words from a given sentence

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

Removing duplicate words from a sentence is a common string manipulation task in C#. This process involves splitting the sentence into individual words, identifying duplicates, and keeping only unique words while preserving the original structure. There are several approaches to accomplish this task, ranging from using LINQ's Distinct() method to using collections like HashSet for efficient duplicate removal. Using LINQ Distinct() Method The Distinct() method from LINQ provides a straightforward way to remove duplicates from a collection − using System; using System.Linq; public class Program { public static void Main() { ...

Read More

C# Program to replace a special character from a String

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

The Replace() method in C# is used to replace all occurrences of a specified character or substring in a string with a new character or substring. This method is particularly useful for removing or replacing special characters from strings. Syntax Following is the syntax for replacing characters using the Replace() method − string.Replace(oldChar, newChar) string.Replace(oldString, newString) Parameters oldChar/oldString − The character or string to be replaced. newChar/newString − The character or string to replace with. Return Value The Replace()

Read More

C# Program to replace a character with asterisks in a sentence

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

The Replace() method in C# is used to replace all occurrences of a specified character or string with another character or string. This method is particularly useful when you need to replace special characters like asterisks with other characters in a sentence. Syntax Following is the syntax for replacing a character using the Replace() method − string newString = originalString.Replace(oldChar, newChar); For replacing a string with another string − string newString = originalString.Replace(oldString, newString); Parameters oldChar/oldString: The character or string to be replaced newChar/newString: The character or string to replace with Return Value The Replace()

Read More

How to find the average of elements of an integer array in C#?

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

Finding the average of elements in an integer array is a common programming task in C#. The average is calculated by dividing the sum of all elements by the total number of elements in the array. Syntax The basic approach involves three steps − int[] array = {element1, element2, element3, ...}; int sum = 0; for (int i = 0; i < array.Length; i++) { sum += array[i]; } int average = sum / array.Length; Using For Loop to Calculate Average The traditional approach uses a for loop to ...

Read More

How to find the product of two binary numbers using C#?

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

To find the product of two binary numbers in C#, we can implement binary multiplication using the traditional algorithm. This involves multiplying each digit of one binary number with the other and adding the results with proper shifting. How Binary Multiplication Works Binary multiplication follows the same principle as decimal multiplication, but uses only 0 and 1. When we multiply by 1, we get the same number; when we multiply by 0, we get zero. The partial products are then added together with appropriate left shifts. Binary Multiplication Process 11100 (28 ...

Read More
Showing 7941–7950 of 21,090 articles
« Prev 1 793 794 795 796 797 2109 Next »
Advertisements