Csharp Articles

Page 122 of 196

C# program to convert floating to binary

Samual Sam
Samual Sam
Updated on 17-Mar-2026 861 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 272 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 766 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

SortedMap Interface in C#

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

In C#, there is no direct equivalent to Java's SortedMap interface. However, C# provides the SortedList and SortedDictionary collections which offer similar functionality for maintaining key-value pairs in sorted order. The SortedList collection in C# uses both a key and an index to access items. It combines the features of an array and a hash table, maintaining items in sorted order based on the key values. You can access items either by index (like an ArrayList) or by key (like a Hashtable). Syntax Following is the syntax for creating a SortedList − SortedList sortedList = ...

Read More

Date format validation using C# Regex

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

Date format validation in C# ensures that user input matches the expected date format before processing. The most reliable approach is using the DateTime.TryParseExact method, which validates both the format and the actual date values. For more complex pattern matching, Regular Expressions (Regex) can also be used. Syntax Following is the syntax for DateTime.TryParseExact method − bool DateTime.TryParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style, out DateTime result) Following is the syntax for Regex date validation − Regex regex = new Regex(@"pattern"); bool isMatch = regex.IsMatch(dateString); ...

Read More
Showing 1211–1220 of 1,951 articles
« Prev 1 120 121 122 123 124 196 Next »
Advertisements