Csharp Articles

Page 120 of 196

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 314 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 1K+ 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 321 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

How to find the length and rank of a jagged array in C#?

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

A jagged array in C# is an array of arrays where each sub-array can have different lengths. Unlike multi-dimensional arrays, jagged arrays provide flexibility in storing varying amounts of data in each row. To find the length and rank of a jagged array, you can use the Length property, GetLowerBound() and GetUpperBound() methods, and the Rank property. Syntax Following is the syntax for declaring a jagged array − dataType[][] arrayName = new dataType[rows][]; Following are the methods and properties to find length and rank − arrayName.Length ...

Read More

How to find the Rank of a given Array in C#?

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

The rank of an array in C# refers to the number of dimensions it has. A one-dimensional array has a rank of 1, a two-dimensional array has a rank of 2, and so on. To find the rank of any array, use the Rank property. Syntax Following is the syntax to get the rank of an array − arrayName.Rank Return Value The Rank property returns an int value representing the number of dimensions in the array. Using Rank Property with Different Array Types Example 1: Single-Dimensional Array using System; ...

Read More
Showing 1191–1200 of 1,951 articles
« Prev 1 118 119 120 121 122 196 Next »
Advertisements