Programming Articles

Page 857 of 2547

C# Enum Format Method

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

The Enum.Format method in C# converts the value of a specified enumerated type to its equivalent string representation according to the specified format. This method provides flexible formatting options including decimal, hexadecimal, and name representations. Syntax Following is the syntax for the Enum.Format method − public static string Format(Type enumType, object value, string format) Parameters enumType − The enumeration type of the value to convert. value − The value to convert. format − The output format to use. Common formats are "G" (name), "D" (decimal), "X" (hexadecimal), and "F" (name if defined, ...

Read More

C# program to find the sum of digits of a number using Recursion

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

A recursive function calls itself with modified parameters until it reaches a base case. To find the sum of digits of a number using recursion, we extract the last digit using the modulus operator (%) and add it to the sum of remaining digits. Syntax Following is the syntax for a recursive function to sum digits − public int SumOfDigits(int number) { if (number == 0) { return 0; // base case } return (number % 10) + SumOfDigits(number / ...

Read More

What does Array.LongLength property of array class do in C#?

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

The Array.LongLength property in C# gets a 64-bit integer (long) that represents the total number of elements in all dimensions of an array. This property is particularly useful when working with very large arrays that might exceed the range of a 32-bit integer. Syntax Following is the syntax for using the LongLength property − long totalElements = arrayName.LongLength; Return Value The property returns a long value representing the total number of elements across all dimensions of the array. Single-Dimensional Array Example For a single-dimensional array, LongLength returns the same value as ...

Read More

What is a static class in C#?

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

A static class in C# is a class that cannot be instantiated and can only contain static members. Static classes are implicitly sealed, meaning they cannot be inherited, and they cannot contain instance constructors or non-static members. Static classes are useful for grouping related utility methods and constants that don't require object instantiation. They are loaded automatically by the .NET runtime when first referenced. Syntax Following is the syntax for declaring a static class − public static class ClassName { public static ReturnType MethodName() { ...

Read More

Initialization vs Instantiation in C#

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

In C#, initialization and instantiation are two fundamental concepts that are often confused. Initialization refers to assigning a value to a variable when it is declared, while instantiation refers to creating a new object instance using the new keyword. Initialization Initialization is the process of assigning a value to a variable at the time of declaration. This can be done for value types, reference types, and collections − Value Type Initialization using System; class Program { public static void Main() { int val = 50; ...

Read More

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
Showing 8561–8570 of 25,466 articles
« Prev 1 855 856 857 858 859 2547 Next »
Advertisements