Csharp Articles

Page 104 of 196

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

What is a static constructor in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 599 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# object serialization

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

Object serialization in C# is the process of converting an object into a stream of bytes for storage or transmission. The serialized data can be saved to files, databases, or sent over a network, and later deserialized back into objects. C# provides several approaches for serialization, including binary serialization, XML serialization, and JSON serialization. Binary serialization preserves the complete object state and type information. Syntax For binary serialization using BinaryFormatter − [Serializable] public class ClassName { // class members } BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, objectInstance); For deserialization ...

Read More

How to access elements from multi-dimensional array in C#?

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

To access elements from a multi-dimensional array in C#, you specify indices for each dimension using square brackets with comma-separated values. For example, a[2, 1] accesses the element at row 3, column 2 (using zero-based indexing). Syntax Following is the syntax for accessing elements from a multi-dimensional array − arrayName[index1, index2, ...indexN] For a 2D array, you use two indices − int element = array[rowIndex, columnIndex]; Understanding Array Indexing Multi-dimensional arrays use zero-based indexing, meaning the first element is at index [0, 0]. Consider this 4×2 array structure − ...

Read More

How to convert Lower case to Upper Case using C#?

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

To convert lowercase to uppercase in C#, use the ToUpper() method. This method converts all lowercase characters in a string to their uppercase equivalents and returns a new string without modifying the original string. Syntax Following is the syntax for the ToUpper() method − string.ToUpper() string.ToUpper(CultureInfo) Parameters CultureInfo (optional) − Specifies the culture-specific formatting information. If not provided, the current culture is used. Return Value The ToUpper() method returns a new string with all lowercase characters converted to uppercase. The original string remains unchanged. Using ToUpper() Method ...

Read More

Value parameters vs Reference parameters vs Output Parameters in C#

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

In C#, there are three ways to pass parameters to methods: value parameters, reference parameters, and output parameters. Each mechanism behaves differently in terms of how data is passed and whether changes affect the original variables. Syntax Following are the syntax forms for the three parameter types − // Value parameter (default) public void Method(int value) { } // Reference parameter public void Method(ref int value) { } // Output parameter public void Method(out int value) { } Value Parameters Value parameters copy the actual value of an argument into the ...

Read More

How to convert Trigonometric Angles in Radians using C#?

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

To convert trigonometric angles from degrees to radians in C#, multiply the degree value by Math.PI/180. Most trigonometric functions in C# expect angles in radians, so this conversion is essential for accurate calculations. Syntax Following is the syntax for converting degrees to radians − double radians = degrees * (Math.PI / 180.0); Following is the syntax for converting radians to degrees − double degrees = radians * (180.0 / Math.PI); Converting Degrees to Radians Example The following example shows how to properly convert degrees to radians before using ...

Read More

How to access elements from a rectangular array in C#?

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

To access elements from a rectangular array in C#, you need to specify the row and column indices using square brackets. Multi-dimensional arrays are also called rectangular arrays because they form a rectangular structure with fixed dimensions. Syntax Following is the syntax for accessing elements in a rectangular array − dataType[, ] arrayName = new dataType[rows, columns]; arrayName[rowIndex, columnIndex] = value; To retrieve an element − dataType element = arrayName[rowIndex, columnIndex]; Rectangular Array Structure Columns 0 1 2 ...

Read More

How to access elements from an array in C#?

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

Arrays in C# are collections of elements that can be accessed using an index. Array indexing starts from 0, meaning the first element is at index 0, the second at index 1, and so on. Syntax Following is the syntax for accessing array elements by index − arrayName[index] Following is the syntax for declaring and initializing an array − dataType[] arrayName = new dataType[size] {element1, element2, element3}; Using Index to Access Elements Each element in an array has a specific position called an index. You can access any element ...

Read More

How command line arguments are passed in main method in C#?

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

The Main() method is the entry point of a C# application and can accept command line arguments through its args parameter. These arguments allow users to pass data to the program when it starts, making applications more flexible and configurable. Syntax The standard syntax for the Main() method with command line arguments is − static void Main(string[] args) The args parameter is a string array that contains all command line arguments passed to the program − // args[0] = first argument // args[1] = second argument // args.Length = total number of ...

Read More
Showing 1031–1040 of 1,951 articles
« Prev 1 102 103 104 105 106 196 Next »
Advertisements