Articles on Trending Technologies

Technical articles with clear explanations and examples

Unit Testing for C# Code

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

Unit testing is a fundamental practice in C# development that helps maintain code quality throughout the development process. It allows developers to identify problems early in the development cycle and ensures code reliability and reusability. One of the key principles of effective unit testing is following Test Driven Development (TDD) approach, where you write test cases first, then write the minimal code required to make those tests pass. Setting Up Unit Tests in Visual Studio For unit testing in C#, you can use Microsoft's built-in testing framework, commonly known as MS Unit Test. Here's how to create ...

Read More

Buffer GetByte Example in C#

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

The Buffer.GetByte() method in C# allows you to read individual bytes from an array at a specified byte position. This method is useful when you need to examine the binary representation of data stored in arrays of primitive types. Syntax Following is the syntax for the Buffer.GetByte() method − public static byte GetByte(Array array, int index) Parameters array − The source array from which to read the byte. index − The zero-based byte position within the array. Return Value Returns a byte value at the specified position in the ...

Read More

Convert.ToSByte Method in C#

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

The Convert.ToSByte method in C# converts a specified value to an 8-bit signed integer (sbyte). The sbyte data type can store values from -128 to 127 and is useful when you need to work with small signed integers while conserving memory. Syntax The Convert.ToSByte method has several overloads to handle different data types − Convert.ToSByte(value) Convert.ToSByte(value, IFormatProvider) Convert.ToSByte(value, fromBase) Parameters value − The value to be converted to sbyte. Can be of various types including bool, char, decimal, double, float, int, string, etc. provider − An object that supplies culture-specific formatting information ...

Read More

DateTime.GetDateTimeFormats() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 1K+ Views

The DateTime.GetDateTimeFormats() method in C# converts a DateTime instance to all string representations supported by the standard date and time format specifiers. This method is useful for discovering all possible formatted outputs for a given DateTime value. Syntax Following are the two overloads of the method − public string[] GetDateTimeFormats() public string[] GetDateTimeFormats(char format) Parameters format − A standard date and time format character that specifies which format patterns to return (optional). Return Value Returns a string[] containing all possible string representations of the DateTime value using ...

Read More

What is the use of 'Using' statement in C#?

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

The using statement in C# is used for automatic resource management and memory cleanup. It ensures that resources are properly disposed of when they are no longer needed, even if an exception occurs. The using statement works with objects that implement the IDisposable interface. The main goal of the using statement is to manage resources and automatically release them when the code block completes execution. This is particularly useful for file operations, database connections, and other system resources that need explicit cleanup. Syntax Following is the syntax for the using statement − using (ResourceType resource ...

Read More

Initializing HashSet in C#

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

A HashSet in C# is a collection that stores unique elements and automatically eliminates duplicates. It provides fast lookups and is ideal when you need to ensure all elements are distinct. Syntax Following is the syntax for initializing a HashSet − var hashSet = new HashSet(); var hashSet = new HashSet(collection); var hashSet = new HashSet { element1, element2, element3 }; Using Array to Initialize HashSet You can initialize a HashSet with an existing array. The HashSet will automatically remove any duplicate values from the array − using System; using System.Collections.Generic; ...

Read More

Use ReaderWriter Lock in C#

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

The ReaderWriterLock class in C# provides synchronized access to a resource by allowing multiple threads to read simultaneously while ensuring exclusive access for writing operations. It offers better performance than Monitor for scenarios where reads are frequent and writes are infrequent. Note: ReaderWriterLock is obsolete since .NET 3.5. The recommended alternative is ReaderWriterLockSlim, which provides better performance and functionality. Syntax Following is the syntax for declaring a ReaderWriterLock − static ReaderWriterLock rwLock = new ReaderWriterLock(); Following is the syntax for acquiring and releasing locks − // Acquire reader lock rwLock.AcquireReaderLock(timeout); try ...

Read More

Convert.ToInt64 Method in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 731 Views

The Convert.ToInt64 method in C# converts a specified value to a 64-bit signed integer (long). This method can convert various data types including strings, floating-point numbers, and other numeric types to a long value. Syntax Following are the common syntax overloads for Convert.ToInt64 − public static long ToInt64(object value); public static long ToInt64(string value); public static long ToInt64(double value); public static long ToInt64(float value); public static long ToInt64(decimal value); Parameters value − The value to convert to a 64-bit signed integer Return Value Returns a 64-bit signed integer (long) ...

Read More

How to create a thread in C#?

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

Threads are lightweight processes that represent independent execution paths within a program. In C#, threads are created using the Thread class from the System.Threading namespace. Creating threads enables concurrent programming, allowing multiple operations to run simultaneously and improving application efficiency. Modern operating systems use threads to implement concurrent programming, which saves CPU cycles and increases application performance by allowing multiple tasks to execute in parallel. Syntax Following is the basic syntax for creating a thread in C# − Thread threadName = new Thread(methodName); threadName.Start(); You can also use a ThreadStart delegate to wrap ...

Read More

What are destructors in C# programs?

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

A destructor is a special member function of a class that is executed whenever an object of its class goes out of scope or is garbage collected. It performs cleanup operations before the object is destroyed from memory. A destructor has exactly the same name as the class with a prefixed tilde (~), and it cannot have parameters or return values. It is automatically called by the garbage collector, not directly by the programmer. Syntax Following is the syntax for declaring a destructor − ~ClassName() { // cleanup code } ...

Read More
Showing 10631–10640 of 61,297 articles
Advertisements