Csharp Articles

Page 119 of 196

CopyOnWriteArrayList version in C#

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

While Java has CopyOnWriteArrayList, C# does not have a direct equivalent. Instead, the SynchronizedCollection class in C# provides thread-safe collection operations. Unlike Java's copy-on-write approach, SynchronizedCollection uses locking mechanisms to ensure thread safety. Syntax Following is the syntax for declaring a SynchronizedCollection − public class SynchronizedCollection : IList, ICollection, IEnumerable, IEnumerable, IList, ICollection Where T is the type of objects in the collection. Properties The SynchronizedCollection class provides the following key properties − Property Description Count Gets the number of ...

Read More

What is the Mutex class in C#?

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

The Mutex class in C# is a synchronization primitive that provides mutually exclusive access to a shared resource. Unlike other synchronization mechanisms, Mutex can be used for both thread synchronization within a single process and interprocess synchronization across multiple processes. The name "Mutex" stands for mutual exclusion, ensuring that only one thread can access a protected resource at a time. Syntax Following are the common ways to create a Mutex instance − // Default constructor Mutex mutex = new Mutex(); // With initial ownership Mutex mutex = new Mutex(bool initiallyOwned); // With initial ...

Read More

What is the difference between public, static and void keywords in C#?

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

The public, static, and void keywords in C# have specific meanings and are commonly seen together in the Main method of any C# program. Understanding these keywords is essential for C# programming as they control access, memory allocation, and return behavior of methods. The Main method serves as the entry point for all C# programs, defining what a class does when executed. Syntax Following is the typical syntax of the Main method showing all three keywords − public static void Main(string[] args) { // program execution starts here } ...

Read More

What is the equivalent of a VB module in C#?

George John
George John
Updated on 17-Mar-2026 1K+ Views

In VB.NET, a module is used to store loose code and variables that are accessible from anywhere in the application without needing to instantiate an object. Variables in a module maintain their state throughout the application lifetime. The C# equivalent of a VB.NET module is a static class. Static classes provide the same functionality − global accessibility without instantiation and persistent state through static members. Syntax Following is the syntax for creating a static class in C# − public static class ClassName { public static void MethodName() { ...

Read More

Reverse a Stack using C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 4K+ Views

A stack is a Last-In-First-Out (LIFO) data structure in C#. To reverse a stack, we can use another stack and leverage the LIFO property by popping elements from the original stack and pushing them into a new stack. The System.Collections.Stack class provides Push() and Pop() methods that make stack reversal straightforward. Syntax Following is the basic syntax for creating and reversing a stack − Stack originalStack = new Stack(); Stack reversedStack = new Stack(); while (originalStack.Count != 0) { reversedStack.Push(originalStack.Pop()); } How Stack Reversal Works The reversal process ...

Read More

Sorting a String in C#

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

Sorting a string array in C# is accomplished using the Array.Sort() method, which arranges elements in alphabetical order. This method modifies the original array and uses lexicographic comparison by default. Syntax Following is the basic syntax for sorting a string array − Array.Sort(arrayName); For custom sorting, you can use an overloaded version − Array.Sort(arrayName, StringComparer.OrdinalIgnoreCase); Using Array.Sort() for String Arrays The Array.Sort() method sorts string arrays in ascending alphabetical order. Here's how it works − using System; public class Program { public static ...

Read More

How to compile and execute C# programs on Mac OS?

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

To compile and execute C# programs on Mac OS, you need an Integrated Development Environment (IDE) or compiler toolchain. Mac OS offers several excellent options for C# development, ranging from full-featured IDEs to lightweight editors and command-line tools. The most popular and recommended approach is using Visual Studio for Mac or the newer Visual Studio Code with the C# extension. Additionally, you can use the .NET CLI for command-line compilation and execution. Using Visual Studio for Mac Visual Studio for Mac is a native macOS IDE specifically designed for .NET development. It provides IntelliSense, debugging tools, and ...

Read More

How to compile and execute C# programs on Linux?

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

To compile and execute C# programs on Linux, you have several options. The modern approach is to use the .NET SDK, which provides a cross-platform runtime and compiler. You can also use IDEs like MonoDevelop or Visual Studio Code for development. The .NET SDK is Microsoft's official cross-platform development platform that runs natively on Linux. MonoDevelop is an open-source IDE that allows you to run C# on multiple platforms including Windows, Linux, and macOS. MonoDevelop is also known as Xamarin Studio and includes a C# compiler. Installing .NET SDK on Linux The .NET SDK is the recommended ...

Read More

How to find the length of jagged array using a property?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

A jagged array in C# is an array of arrays where each inner array can have different lengths. To find the length of a jagged array, you use the Length property, which returns the number of inner arrays (rows) in the jagged array. Syntax Following is the syntax for declaring a jagged array − dataType[][] arrayName = new dataType[size][]; To get the length of a jagged array, use the Length property − int numberOfRows = arrayName.Length; Jagged Array Structure [0, 0] ...

Read More

C# program to check if two lists have at-least one element common

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

A common requirement in C# programming is to check if two lists share at least one common element. This can be achieved using various approaches, from simple nested loops to more efficient methods using HashSets and LINQ. The most efficient approach is to use HashSet operations or LINQ's Intersect() method, which provide optimal performance for finding common elements between collections. Using HashSet Intersection HashSet provides an Overlaps() method that efficiently checks if two sets have any common elements − using System; using System.Collections.Generic; public class Program { public static void ...

Read More
Showing 1181–1190 of 1,951 articles
« Prev 1 117 118 119 120 121 196 Next »
Advertisements