Articles on Trending Technologies

Technical articles with clear explanations and examples

How to iterate two Lists or Arrays with one foreach statement in C#?

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

When working with multiple collections in C#, you often need to iterate through them simultaneously. The Zip() method from LINQ provides an elegant solution to combine two arrays or lists and iterate them with a single foreach statement. Syntax Following is the syntax for using the Zip() method to combine two collections − var result = collection1.Zip(collection2, (item1, item2) => new { Prop1 = item1, Prop2 = item2 }); The lambda expression defines how to combine elements from both collections into a new anonymous object. Using Zip() with Arrays The Zip() method ...

Read More

What is the use of 'new' keyword in C#?

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

The new keyword in C# serves multiple important purposes. It is primarily used to create new instances of classes, allocate memory for arrays, and hide inherited members from base classes. Syntax Following is the syntax for creating object instances using new − ClassName objectName = new ClassName(); Following is the syntax for creating arrays using new − dataType[] arrayName = new dataType[size]; Following is the syntax for hiding base class members using new − public new void MethodName() { // hides the base class method ...

Read More

How to pop the first element from a C# List?

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

To pop the first element from a C# List, you can use the RemoveAt() method with index 0. This method removes the element at the specified position and shifts all subsequent elements one position to the left. Unlike traditional stack pop operations that return the removed element, RemoveAt() only removes the element. If you need both removal and retrieval, you must first get the element before removing it. Syntax Following is the syntax for removing the first element − list.RemoveAt(0); Following is the syntax for popping (retrieving and removing) the first element − ...

Read More

C# program to find the length of the Longest Consecutive 1's in Binary Representation of a given integer

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

Finding the longest consecutive 1's in the binary representation of a number is a common bit manipulation problem. The key is to use the bitwise AND operation combined with left shift to eliminate consecutive 1's one group at a time. Syntax The core operation uses bitwise AND with left shift − i = (i & (i

Read More

C# Program to get the type of the specified Enumeration

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

Use the GetType() method to get the type of the specified enumeration in C#. This method returns a Type object that represents the actual enumeration type, which is useful for reflection, debugging, and type checking operations. When working with enumeration values, you can retrieve both the enumeration type and its underlying type using built-in methods provided by the Enum class and Type class. Syntax Following is the syntax for getting the type of an enumeration − Type enumType = enumValue.GetType(); To get the underlying type of an enumeration − Type underlyingType ...

Read More

What is the Values property of Hashtable class in C#?

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

The Values property of the Hashtable class in C# gets an ICollection containing all the values stored in the Hashtable. This property provides a way to access all values without needing to know their corresponding keys. Syntax Following is the syntax for using the Values property − public virtual ICollection Values { get; } To iterate through the values − foreach (object value in hashtable.Values) { // process each value } Return Value The Values property returns an ICollection object that contains all the values ...

Read More

C# int.Parse Vs int.TryParse Method

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

The int.Parse and int.TryParse methods in C# are used to convert string representations of numbers to integers. The key difference lies in how they handle conversion failures: int.Parse throws an exception when the string cannot be converted, while int.TryParse returns a boolean value indicating success or failure. Syntax Following is the syntax for int.Parse method − int result = int.Parse(string); Following is the syntax for int.TryParse method − bool success = int.TryParse(string, out int result); Using int.Parse Method The int.Parse method directly converts a valid string to an integer. ...

Read More

C# Enum GetValues Method

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

The Enum.GetValues() method in C# retrieves an array containing the values of all constants in a specified enumeration. This method is useful when you need to iterate through all enum values dynamically or perform operations on the entire set of enum values. Syntax Following is the syntax for the Enum.GetValues() method − public static Array GetValues(Type enumType) Parameters enumType − The Type of the enumeration whose values you want to retrieve. Return Value Returns an Array containing the values of the constants in the specified enumeration. Using GetValues() ...

Read More

Checked vs Unchecked Exceptions in C#

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

The checked and unchecked keywords in C# control whether arithmetic operations throw exceptions when overflow occurs. By default, C# ignores arithmetic overflow in most contexts, but you can explicitly enable or disable overflow checking using these keywords. In a checked context, arithmetic overflow throws an OverflowException. In an unchecked context, overflow is ignored and the result wraps around to the valid range. Syntax Following is the syntax for checked operations − int result = checked(expression); checked { // multiple statements } Following is the syntax for unchecked operations − ...

Read More

C# Program to remove duplicate characters from String

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

Removing duplicate characters from a string is a common programming task in C#. There are several approaches to achieve this, with HashSet being one of the most efficient methods due to its automatic handling of unique elements. Using HashSet to Remove Duplicates The HashSet collection automatically maintains unique elements, making it perfect for removing duplicate characters from a string − using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string myStr = "kkllmmnnoo"; Console.WriteLine("Initial String: ...

Read More
Showing 11261–11270 of 61,297 articles
Advertisements