Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 781 of 2109
How to count the number of items in a C# list?
The Count property in C# is used to determine the number of elements in a List. This property returns an integer representing the total count of items currently stored in the list. Syntax Following is the syntax for using the Count property − int count = myList.Count; Parameters The Count property does not take any parameters. It is a read-only property that returns the current number of elements in the list. Return Value The Count property returns an int value representing the number of elements in the list. It returns 0 ...
Read MoreHow to create a Dictionary using C#?
A Dictionary in C# is a collection of key-value pairs where each key is unique. The Dictionary class is part of the System.Collections.Generic namespace and provides fast lookups based on keys. Dictionaries are useful when you need to associate values with unique identifiers, such as storing employee IDs with names or product codes with prices. Syntax Following is the syntax for creating a Dictionary − Dictionary dictionaryName = new Dictionary(); Following is the syntax for adding items to a Dictionary − dictionaryName.Add(key, value); dictionaryName[key] = value; // Alternative syntax ...
Read MoreHow to create a Directory using C#?
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 MoreVariable Arguments (Varargs) in C#
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 MoreHow to define character constants in C#?
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 MoreWhat is the System.Reflection.Module in C#?
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 MoreHow to add items to a list in C#?
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 MoreHow to add integer values to a C# list?
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 MoreHow to add read-only property in C#?
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 MoreAn array of streams in C#
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