Programming Articles

Page 108 of 2547

How to find maximum between 2 numbers using C#?

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

Finding the maximum between two numbers in C# can be accomplished using several approaches. The most common methods include using conditional statements, the Math.Max() method, and the ternary operator. Using If-Else Statement The traditional approach uses an if-else statement to compare two numbers and determine which one is larger − using System; class Program { static void Main(string[] args) { int num1 = 50; int num2 = 90; ...

Read More

Insertion Sort in C#

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

Insertion Sort is a simple sorting algorithm that builds the sorted array one element at a time. It takes each element from the unsorted portion and inserts it into its correct position within the already sorted portion of the array. The algorithm works similarly to how you might sort playing cards in your hand − you pick up cards one by one and insert each into its proper position among the cards you've already sorted. How Insertion Sort Works The algorithm divides the array into two parts: a sorted portion (initially just the first element) and an ...

Read More

Thread-Safe collections in C#

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

Thread-safe collections in C# are specialized data structures designed for concurrent programming. The System.Collections.Concurrent namespace, introduced in .NET Framework 4, provides collections that allow multiple threads to safely add, remove, and access items without external synchronization. These collections use lightweight synchronization mechanisms like SpinLock and SpinWait to achieve thread safety while maintaining high performance and scalability. Thread-Safe Collections Overview Thread A Thread B Thread C Concurrent Collection ...

Read More

C# program to count number of bytes in an array

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

In C#, you can count the number of bytes in an array using the Buffer.ByteLength() method. This method returns the total number of bytes occupied by all elements in the array, which is particularly useful when working with different data types that have varying byte sizes. Syntax Following is the syntax for using Buffer.ByteLength() − int byteCount = Buffer.ByteLength(array); Parameters array − The array whose byte length you want to determine. It must be an array of primitive types. Return Value The method returns an int representing ...

Read More

C# Program to check whether a node is a LinkedList or not

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

The Contains() method in C# is used to check whether a specific value exists in a LinkedList. This method searches through all nodes in the LinkedList and returns a boolean value indicating whether the specified element is found. Syntax Following is the syntax for using the Contains() method − public bool Contains(T item) Parameters item − The value to locate in the LinkedList. Return Value Returns true if the item is found in the LinkedList; otherwise, false. LinkedList Contains() Method ...

Read More

Char.IsUpper() Method in C#

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

The Char.IsUpper() method in C# determines whether a specified Unicode character is categorized as an uppercase letter. It returns true if the character is an uppercase letter, otherwise false. Syntax Following is the syntax of the Char.IsUpper() method − public static bool IsUpper(char ch); Parameters ch − The Unicode character to evaluate. Return Value This method returns a bool value − true if the character is an uppercase letter false if the character is not an uppercase letter Using ...

Read More

c# Put spaces between words starting with capital letters

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

To place spaces between words starting with capital letters in C#, you can use LINQ to examine each character and insert spaces before uppercase letters. This technique is commonly used to format PascalCase strings into readable text. Syntax The basic syntax using LINQ to add spaces before capital letters − string.Concat(str.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' '); Using LINQ with Select and IsUpper The following example demonstrates how to add spaces before each uppercase letter in a PascalCase string − using System; using System.Linq; class Demo ...

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

Buffer GetByte Example in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 291 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 343 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
Showing 1071–1080 of 25,467 articles
« Prev 1 106 107 108 109 110 2547 Next »
Advertisements