Server Side Programming Articles

Page 799 of 2109

C# program to merge two Dictionaries

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

Merging dictionaries in C# involves combining two or more Dictionary objects into one. This can be useful when you need to consolidate data from different sources or combine configuration settings. There are several approaches to merge dictionaries, each with different behaviors for handling duplicate keys. Syntax Following is the syntax for creating dictionaries − Dictionary dict = new Dictionary(); Following is the syntax for adding elements − dict.Add(key, value); dict[key] = value; // overwrites if key exists Using HashSet to Merge Keys Only This approach merges only the ...

Read More

Semaphore in C#

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

A Semaphore in C# is a synchronization primitive that controls access to a pool of resources by allowing a specified number of threads to enter a critical section simultaneously. It maintains a count of available permits and blocks threads when the limit is reached. The System.Threading.Semaphore class provides all the methods and properties needed to implement semaphore functionality in multithreaded applications. Syntax The basic syntax for creating a semaphore − Semaphore semaphore = new Semaphore(initialCount, maximumCount); To acquire and release the semaphore − semaphore.WaitOne(); // Acquire the semaphore ...

Read More

How to convert an array of characters into a string in C#?

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

Converting an array of characters into a string is a common operation in C#. There are multiple approaches to accomplish this, each suitable for different scenarios. Syntax Following is the syntax for converting a character array to string using the string constructor − string str = new string(charArray); Following is the syntax using the string constructor with range specification − string str = new string(charArray, startIndex, length); Using String Constructor The simplest way to convert a character array to a string is using the string constructor that accepts a ...

Read More

How to convert a string into int in C#?

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

Converting a string to an integer in C# is a common task that can be accomplished using several methods. The most straightforward approach is using Int32.Parse() method, which converts the string representation of a number to its 32-bit signed integer equivalent. Syntax Following is the syntax for using Int32.Parse() method − int result = Int32.Parse(stringValue); Following is the syntax for using Convert.ToInt32() method − int result = Convert.ToInt32(stringValue); Following is the syntax for using int.TryParse() method − bool success = int.TryParse(stringValue, out int result); Using Int32.Parse() ...

Read More

Valid variant of Main() in C#

varun
varun
Updated on 17-Mar-2026 821 Views

The Main method is the entry point for all C# programs. It defines what the class does when executed. When you run a C# application, the runtime looks for the Main method and begins execution from there. Syntax There are several valid variants of the Main method in C# − static void Main() static void Main(string[] args) static int Main() static int Main(string[] args) Parameters static − the object is not needed to access static members. The Main method must be static so the runtime can call it without creating an ...

Read More

Main thread vs child thread in C#

varma
varma
Updated on 17-Mar-2026 981 Views

In C#, every application starts with a main thread that executes the Main method. Additional threads, called child threads, can be created to perform concurrent operations alongside the main thread. Main Thread The main thread is automatically created when a C# program starts execution. It is the first thread to run in a process and is responsible for executing the Main method. The main thread can create and manage other threads during program execution. Child Thread A child thread is any thread created from the main thread using the Thread class or other threading mechanisms. Child ...

Read More

How to initialize a dictionary to an empty dictionary in C#?

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

To initialize a dictionary to an empty state in C#, there are several approaches. You can create a new empty dictionary directly, use the Clear() method to empty an existing dictionary, or check if a dictionary is already empty using the Count property. Syntax Following is the syntax for creating an empty dictionary − Dictionary dict = new Dictionary(); Following is the syntax for clearing an existing dictionary − dict.Clear(); Following is the syntax for checking if a dictionary is empty − if (dict.Count == 0) { ...

Read More

How to input multiple values from user in one line in C#?

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

In C#, you can input multiple values from the user in one line using several approaches. The most common method is using Console.ReadLine() with Split() to parse space-separated or comma-separated values into an array. Syntax Following is the syntax for reading multiple values in one line using Split() − string input = Console.ReadLine(); string[] values = input.Split(' '); // or Split(', ') for comma-separated For converting to integers − int[] numbers = input.Split(' ').Select(int.Parse).ToArray(); Using Split() with Space Separator This approach reads a single line of space-separated values and ...

Read More

How to instantiate a class in C#?

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

In C#, you create an instance of a class using the new operator. This process is called instantiation, which allocates memory for the object and calls the class constructor. Syntax Following is the basic syntax for instantiating a class − ClassName objectName = new ClassName(); For classes with parameterized constructors − ClassName objectName = new ClassName(parameters); Using Default Constructor When you instantiate a class without parameters, it calls the default constructor. Here's an example using a Line class − using System; class Line { ...

Read More

How to iterate any Map in C#

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

C# doesn't have a built-in Map type like Java. Instead, C# uses Dictionary to achieve the same functionality. A Dictionary stores key-value pairs and provides several ways to iterate through its contents. Syntax Following is the syntax for creating a Dictionary − Dictionary dictionary = new Dictionary(); Following are the common iteration patterns − // Iterate over keys foreach (var key in dictionary.Keys) { } // Iterate over values foreach (var value in dictionary.Values) { } // Iterate over key-value pairs foreach (var kvp in dictionary) { } ...

Read More
Showing 7981–7990 of 21,090 articles
« Prev 1 797 798 799 800 801 2109 Next »
Advertisements