CopyOnWriteArrayList version in C#

Arjun Thakur
Updated on 17-Mar-2026 07:04:35

326 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

Delete a file in C#

Ankith Reddy
Updated on 17-Mar-2026 07:04:35

1K+ Views

In C#, you can use the File.Delete() method from the System.IO namespace to delete files from the file system. This method permanently removes the specified file if it exists. Syntax Following is the syntax for deleting a file − File.Delete(string path); Parameters path − A string specifying the path of the file to be deleted. This can be a relative or absolute path. Using File.Delete() Method The File.Delete() method removes the file at the specified path. If the file does not exist, the method does not throw an exception ... Read More

How to add integer values to a C# list?

Samual Sam
Updated on 17-Mar-2026 07:04:35

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

File Permissions in C#

George John
Updated on 17-Mar-2026 07:04:35

3K+ Views

File permissions in C# are managed using the FileIOPermission class from the System.Security.Permissions namespace. This class controls the ability to access files and folders by defining what operations are allowed on specific file system resources. The FileIOPermission class is part of .NET's Code Access Security (CAS) system and helps ensure that applications only perform file operations they are explicitly granted permission to execute. Syntax Following is the syntax for creating a FileIOPermission instance − FileIOPermission permission = new FileIOPermission(PermissionState.None); permission.AllLocalFiles = FileIOPermissionAccess.Read; Following is the syntax for adding specific path permissions − ... Read More

The "E" and "e" custom specifiers in C#

George John
Updated on 17-Mar-2026 07:04:35

478 Views

The "E" and "e" custom specifiers in C# are used to format numbers in scientific notation (exponential notation). When any of these specifiers appear in a format string followed by at least one zero, the number is formatted with an "E" or "e" separator between the mantissa and the exponent. Syntax The following format specifiers create exponential notation − "E0" // Uppercase E with minimum exponent digits "e0" // Lowercase e with minimum exponent digits "E+0" // Uppercase E with explicit + sign "e+0" // Lowercase ... Read More

Draw an ellipse in C#

Samual Sam
Updated on 17-Mar-2026 07:04:35

3K+ Views

To draw an ellipse in C#, you use the DrawEllipse() method from the Graphics class. This method requires a Pen object to define the ellipse's outline and either a Rectangle or coordinate parameters to specify the ellipse's position and size. Drawing ellipses is commonly done in Windows Forms applications using the Paint event handler or by overriding the OnPaint method. Syntax The DrawEllipse() method has several overloads − graphics.DrawEllipse(pen, rectangle); graphics.DrawEllipse(pen, x, y, width, height); Parameters pen − Defines the color, width, and style of the ellipse outline rectangle − Specifies ... Read More

Char.ToString() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

218 Views

The Char.ToString() method in C# is used to convert a character to its equivalent string representation. This method is particularly useful when you need to convert a single character into a string for string operations or concatenation. Syntax Following is the syntax for the Char.ToString() method − public override string ToString(); Return Value The method returns a string object containing the character value converted to its string representation. Using Char.ToString() Method Example 1 - Converting Lowercase Character Let us see an example to convert a lowercase character to its string ... Read More

DateTimeOffset.AddTicks() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

281 Views

The DateTimeOffset.AddTicks() method in C# is used to add a specified number of ticks to the value of a DateTimeOffset instance. A tick represents 100 nanoseconds, making it the smallest unit of time measurement in .NET. Syntax Following is the syntax − public DateTimeOffset AddTicks(long ticks); Parameters ticks: A signed 64-bit integer representing the number of 100-nanosecond ticks to add. To subtract ticks, use a negative value. Return Value Returns a new DateTimeOffset instance with the specified ticks added to the original value. The original instance remains unchanged. Understanding Tick ... Read More

How to add items/elements to an existing jagged array in C#?

Ankith Reddy
Updated on 17-Mar-2026 07:04:35

1K+ Views

Adding items to an existing jagged array in C# can be accomplished through several methods. You can modify individual elements directly, replace entire sub-arrays, or dynamically resize arrays using collections. The approach depends on whether you want to change existing elements or expand the array structure. Understanding Jagged Arrays A jagged array is an array of arrays where each sub-array can have different lengths. Unlike multidimensional arrays, jagged arrays provide flexibility in storing data with varying row sizes. Jagged Array Structure arr[0] arr[1] ... Read More

What is the Mutex class in C#?

Samual Sam
Updated on 17-Mar-2026 07:04:35

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

Advertisements