Articles on Trending Technologies

Technical articles with clear explanations and examples

Common Language Runtime (CLR) in C#.NET

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

The Common Language Runtime (CLR) is the execution environment for .NET applications that manages code execution, memory allocation, and provides essential runtime services. It acts as an intermediary between your C# code and the operating system, converting intermediate language code into machine-specific instructions through just-in-time compilation. The CLR ensures that C# applications run safely and efficiently by providing automatic memory management, exception handling, type safety verification, and cross-language interoperability across all .NET languages. CLR Execution Process C# Code IL Code (Bytecode) ...

Read More

What is a static constructor in C#?

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

A static constructor is a special constructor declared using the static modifier. It is the first block of code executed when a class is accessed for the first time. A static constructor executes only once during the entire lifetime of the application, regardless of how many instances of the class are created. Static constructors are primarily used to initialize static fields or perform one-time setup operations for a class. Syntax Following is the syntax for declaring a static constructor − static ClassName() { // initialization code } Key Rules of ...

Read More

C# Program to return specified number of elements from the beginning of a sequence

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 220 Views

The Take() method in C# is a LINQ extension method that returns a specified number of elements from the beginning of a sequence. This method is particularly useful when you need to retrieve only the first few elements from a collection, especially after sorting or filtering operations. Syntax Following is the syntax for the Take() method − public static IEnumerable Take( this IEnumerable source, int count ) Parameters source − The sequence to return elements from. count − The number of elements to return ...

Read More

Compare two strings lexicographically in C#

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

The String.Compare() method in C# performs lexicographic (alphabetical) comparison between two strings. It compares strings character by character based on their Unicode values and is case-sensitive by default. Syntax Following is the syntax for the basic String.Compare() method − int result = string.Compare(string1, string2); For case-insensitive comparison − int result = string.Compare(string1, string2, true); Return Value The String.Compare() method returns an integer value indicating the lexicographic relationship between the two strings − If str1 is less than str2, it returns -1. If str1 is equal to str2, ...

Read More

Comparison of double and float primitive types in C#

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

In C#, float and double are both floating-point data types used to store decimal numbers, but they differ significantly in precision, memory usage, and range. Understanding these differences is crucial for choosing the right data type for your applications. Syntax Following is the syntax for declaring float and double variables − float floatVariable = 3.14f; double doubleVariable = 3.14159265359; Note the f suffix for float literals and optional d suffix for double literals − float price = 19.99f; double pi = 3.14159265359d; // 'd' is optional for double Key Differences ...

Read More

Understanding IndexOutOfRangeException Exception in C#

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

The IndexOutOfRangeException is a common runtime exception in C# that occurs when you attempt to access an array element using an index that is outside the valid range of indices for that array. This exception helps prevent memory corruption by catching invalid array access attempts. Arrays in C# are zero-indexed, meaning the first element is at index 0, and the last element is at index length - 1. Attempting to access an index less than 0 or greater than or equal to the array length will throw this exception. When IndexOutOfRangeException Occurs This exception is thrown in ...

Read More

Sorting a HashMap according to keys in C#

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

In C#, the equivalent of Java's HashMap is the Dictionary class, which stores key-value pairs. Sorting a Dictionary by keys requires extracting the keys, sorting them, and then accessing the values in the sorted order. Syntax Following is the syntax for creating and sorting a Dictionary by keys − Dictionary dict = new Dictionary(); // Sort keys using LINQ var sortedByKeys = dict.OrderBy(x => x.Key); // Or extract and sort keys manually var keys = dict.Keys.ToList(); keys.Sort(); Using LINQ OrderBy Method The most efficient way to sort a Dictionary by keys ...

Read More

Does declaring an array create an array in C#?

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

Declaring an array in C# does not create the actual array object in memory. Array declaration only creates a reference variable that can point to an array object. The array must be explicitly initialized using the new keyword to allocate memory and create the array instance. Array Declaration vs Array Creation Understanding the difference between declaration and creation is crucial for working with arrays in C# − Array Declaration vs Creation Declaration Only int[] arr; • Creates reference variable • No memory ...

Read More

C# Program to access tuple elements

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

In C#, tuples are data structures that can hold multiple values of different types. Once you create a tuple, you can access its elements using the Item properties, where each element is numbered starting from Item1. Syntax Following is the syntax for creating a tuple using Tuple.Create() − var tupleName = Tuple.Create(value1, value2, value3, ...); Following is the syntax for accessing tuple elements − tupleName.Item1 // First element tupleName.Item2 // Second element tupleName.Item3 // Third element Using Item Properties to Access Elements Create a tuple with ...

Read More

Chained Exceptions in C#

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

Chained exceptions in C# allow you to preserve the original exception information while throwing a new exception. This creates a chain of exceptions where each exception wraps the previous one, maintaining the complete error context throughout the call stack. When an exception occurs deep in your application, chained exceptions help maintain the full error history by wrapping the original exception inside a new one using the innerException parameter of the Exception constructor. Syntax Following is the syntax for creating a chained exception − try { // code that might throw exception } ...

Read More
Showing 11241–11250 of 61,297 articles
Advertisements