Server Side Programming Articles

Page 797 of 2109

Find free disk space using C#

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

The DriveInfo class in C# provides information about drives and their storage capacity. You can use this class to find free disk space, total disk space, and calculate the percentage of available space on any drive. Syntax Following is the syntax for creating a DriveInfo instance − DriveInfo driveInfo = new DriveInfo("driveLetter"); Following are the key properties for disk space information − long availableSpace = driveInfo.AvailableFreeSpace; long totalSpace = driveInfo.TotalSize; long usedSpace = driveInfo.TotalSize - driveInfo.AvailableFreeSpace; Using DriveInfo to Get Free Disk Space Example using System; using ...

Read More

How to check if a string is a valid keyword in C#?

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

To check if a string is a valid keyword in C#, you can use the IsValidIdentifier method from the CodeDomProvider class. This method determines whether a given string is a valid identifier or a reserved keyword in C#. The IsValidIdentifier method returns true if the string is a valid identifier (like variable names, method names), and false if it's a reserved keyword (like for, if, class, etc.). Syntax Following is the syntax for using IsValidIdentifier method − CodeDomProvider provider = CodeDomProvider.CreateProvider("C#"); bool isIdentifier = provider.IsValidIdentifier(stringToCheck); Using IsValidIdentifier to Check Keywords Here's how ...

Read More

C# program to convert floating to binary

Samual Sam
Samual Sam
Updated on 17-Mar-2026 865 Views

Converting a floating-point number to binary representation in C# involves separating the number into its integer and fractional parts, then converting each part separately using different algorithms. The integer part is converted using repeated division by 2, while the fractional part is converted using repeated multiplication by 2. Algorithm The conversion process follows these steps − Separate the floating-point number into integer and fractional parts Convert the integer part by repeatedly dividing by 2 and collecting remainders Convert the fractional part by repeatedly multiplying by 2 and collecting integer parts Combine both parts with a ...

Read More

How to check if array contains a duplicate number using C#?

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

Checking if an array contains duplicate numbers is a common programming task in C#. There are multiple approaches to solve this problem, ranging from simple loops to LINQ methods and hash-based techniques. Using Dictionary to Count Occurrences The dictionary approach counts the frequency of each element in the array. Any element with a count greater than 1 is a duplicate − using System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { ...

Read More

Singleton Class in C#

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

A Singleton class in C# is a design pattern that ensures only one instance of a class can be created throughout the application's lifetime. It provides a global point of access to that instance and is commonly used for logging, database connections, and configuration management. The key principle of the Singleton pattern is to restrict instantiation of a class to a single object by using a private constructor and providing a static method or property to access the instance. Syntax Following is the basic syntax for implementing a Singleton class − public class Singleton { ...

Read More

Singly LinkedList Traversal using C#

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

A LinkedList in C# is a doubly-linked list that allows efficient insertion and removal of elements. Traversal refers to visiting each node in the LinkedList sequentially to access or process the data. The LinkedList class in C# provides various methods to traverse through its elements, with the most common approach being the foreach loop. Syntax Following is the syntax for declaring a LinkedList − var linkedList = new LinkedList(); Following is the syntax for traversing a LinkedList using foreach − foreach(var item in linkedList) { // Process each ...

Read More

Socket Programming in C#

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

Socket programming in C# enables network communication between applications using the System.Net.Sockets namespace. This namespace provides a managed implementation of the Windows Sockets interface for creating client-server applications that communicate over TCP/IP networks. Socket programming has two basic modes − synchronous (blocking) and asynchronous (non-blocking) operations. Socket Class Constructor Syntax Following is the syntax for creating a Socket instance − Socket socket = new Socket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType); Parameters AddressFamily − Specifies the addressing scheme (InterNetwork for IPv4, InterNetworkV6 for IPv6) SocketType − Defines the type ...

Read More

Thread Synchronization in C#

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

Thread synchronization in C# is essential for coordinating access to shared resources in multithreaded applications. It prevents race conditions and ensures data consistency by controlling how multiple threads access critical sections of code. C# provides several synchronization mechanisms including the lock statement, Mutex class, and other primitives to manage concurrent thread execution effectively. Syntax Following is the syntax for using the lock statement − lock (syncObject) { // critical section code } Following is the syntax for creating and using a Mutex − private static Mutex mutex ...

Read More

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

Sort the words in lexicographical order in C#

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

Lexicographical order means sorting strings alphabetically, similar to how words are arranged in a dictionary. In C#, there are multiple ways to sort an array of strings in lexicographical order using built-in methods and LINQ. Syntax Using LINQ query syntax − var sorted = from word in array orderby word select word; Using Array.Sort() method − Array.Sort(array); Using LINQ OrderBy() method − ...

Read More
Showing 7961–7970 of 21,090 articles
« Prev 1 795 796 797 798 799 2109 Next »
Advertisements