Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 797 of 2547
Convert.ToSByte Method in C#
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 MoreDateTime.GetDateTimeFormats() Method in C#
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 MoreWhat is the use of 'Using' statement in C#?
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 MoreInitializing HashSet in C#
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 MoreUse ReaderWriter Lock in C#
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 MoreConvert.ToInt64 Method in C#
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 MoreHow to create a thread in C#?
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 MoreWhat are destructors in C# programs?
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 MoreMerge two arrays using C# AddRange() method
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 MoreC# program to remove the first occurrence of a node in a Linked List
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