Csharp Articles

Page 106 of 196

How to create a Directory using C#?

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

To create, move, and delete directories in C#, the System.IO.Directory class provides essential methods for directory operations. The Directory.CreateDirectory() method is used to create new directories at specified paths. Syntax Following is the syntax for creating a directory using Directory.CreateDirectory() method − Directory.CreateDirectory(string path); Following is the syntax for checking if a directory exists before creating it − if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } Parameters path − A string representing the directory path to create. Can be an absolute or relative path. ...

Read More

Variable Arguments (Varargs) in C#

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

The params keyword in C# allows a method to accept a variable number of arguments of the same type. This feature, known as variable arguments or varargs, enables you to call a method with any number of parameters without creating an array explicitly. Syntax Following is the syntax for declaring a method with variable arguments − public static returnType MethodName(params type[] parameterName) { // method body } The params keyword must be the last parameter in the method signature, and only one params parameter is allowed per method. Key Rules ...

Read More

How to define character constants in C#?

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

Character constants in C# are single characters enclosed in single quotes. They can be stored in variables of type char and represent individual characters, escape sequences, or Unicode characters. Syntax Following is the syntax for defining character constants − char variableName = 'character'; Character constants can be − Plain characters: 'a', 'X', '5' Escape sequences: '', '\t', ''' Unicode characters: '\u0041' (represents 'A') Common Character Constants Here are the most commonly used character escape sequences − Escape Sequence Character Description ...

Read More

What is the System.Reflection.Module in C#?

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

The System.Reflection.Module class in C# represents a module, which is a portable executable file containing one or more classes and interfaces. It is part of the System.Reflection namespace that allows you to examine and manipulate metadata about types, assemblies, and modules at runtime. A module is essentially a single file within an assembly. Most .NET applications consist of a single module that matches the assembly, but complex applications can have multiple modules within one assembly. Key Properties and Methods The Module class provides several important properties and methods for reflection − Assembly − Gets the ...

Read More

How to add items to a list in C#?

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

In C#, you can add items to a List using several methods. The most common approach is using the Add() method to add single items, but there are also methods to add multiple items at once. Syntax Following is the syntax for creating a list and adding items − var listName = new List(); listName.Add(item); To add multiple items at once − listName.AddRange(collection); Using Add() Method The Add() method adds a single item to the end of the list − using System; using System.Collections.Generic; public class ...

Read More

How to add integer values to a C# list?

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

To add integer values to a List in C#, you can use several methods including Add(), AddRange(), and collection initializer syntax. The Add() method is the most common way to add individual values one at a time. Syntax Following is the syntax for declaring an integer list and adding values − List listName = new List(); listName.Add(value); To add multiple values at once using AddRange() − listName.AddRange(new int[] { value1, value2, value3 }); Using collection initializer syntax − List listName = new List { value1, value2, value3 }; ...

Read More

How to add read-only property in C#?

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

A read-only property in C# is a property that can only be set during object initialization and cannot be modified afterward. There are several ways to create read-only properties, including using the readonly keyword with fields, properties with only getters, and init-only properties (available in C# 9.0+). Syntax Following is the syntax for a read-only field − readonly dataType fieldName; Following is the syntax for a read-only property with only a getter − public dataType PropertyName { get; } Following is the syntax for an init-only property (C# 9.0+) − ...

Read More

An array of streams in C#

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

An array of streams in C# refers to using arrays or collections along with stream objects like StreamWriter and StreamReader to perform file I/O operations. This approach is commonly used when you need to write multiple data items from an array to a file or read file content into an array structure. Syntax Following is the syntax for writing array data to a file using StreamWriter − using (StreamWriter writer = new StreamWriter("filename.txt")) { foreach (dataType item in arrayName) { writer.WriteLine(item); ...

Read More

How to copy or clone a C# list?

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

Copying or cloning a C# list means creating a duplicate of the original list. There are several approaches to accomplish this, each suitable for different scenarios. The choice depends on whether you need a shallow copy or deep copy, and the target data structure. Syntax Following are the common syntaxes for copying a list − // Using constructor List newList = new List(originalList); // Using ToList() method List newList = originalList.ToList(); // Using CopyTo() method T[] array = new T[originalList.Count]; originalList.CopyTo(array); Using List Constructor The most straightforward way to clone a ...

Read More

What is boxing in C#?

George John
George John
Updated on 17-Mar-2026 585 Views

Boxing in C# is the process of converting a value type to an object type. When boxing occurs, the value stored on the stack is copied to an object stored on the heap memory. This is an implicit conversion that allows value types to be treated as reference types. Syntax Boxing happens implicitly when a value type is assigned to an object variable − int valueType = 50; object boxedValue = valueType; // implicit boxing Unboxing requires explicit casting to convert back to the original value type − object boxedValue = 50; ...

Read More
Showing 1051–1060 of 1,951 articles
« Prev 1 104 105 106 107 108 196 Next »
Advertisements