Programming Articles

Page 797 of 2547

Convert.ToSByte Method in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 349 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 885 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 724 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 755 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

Merge two arrays using C# AddRange() method

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

The AddRange() method in C# is used to add elements from a collection to the end of a List. This method is particularly useful for merging arrays by first converting them to a list, adding both arrays using AddRange(), and then converting the result back to an array. Syntax Following is the syntax for the AddRange() method − public void AddRange(IEnumerable collection) Parameters collection − The collection whose elements should be added to the end of the List. The collection itself cannot be null, but it can contain elements that are null. ...

Read More

C# program to remove the first occurrence of a node in a Linked List

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

The LinkedList class in C# provides an efficient way to store and manipulate collections of data. When you need to remove the first occurrence of a specific node from a LinkedList, you can use the Remove() method, which searches for the specified value and removes its first occurrence. Syntax The syntax for removing the first occurrence of a node from a LinkedList is − bool result = linkedList.Remove(value); Parameters value − The value to remove from the LinkedList. The method removes the first node that contains this value. Return Value The Remove()

Read More
Showing 7961–7970 of 25,466 articles
« Prev 1 795 796 797 798 799 2547 Next »
Advertisements