Programming Articles

Page 805 of 2547

How to perform Merge Sort using C#?

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

Merge Sort is a sorting algorithm that uses the divide and conquer method. It divides the array into two halves, recursively sorts each half, and then merges them back together in sorted order. This process continues until the entire array is sorted. How Merge Sort Works Merge Sort follows these steps − Divide: Split the array into two halves at the middle point Conquer: Recursively sort both halves Merge: Combine the two sorted halves into a single sorted array Merge Sort Divide and Conquer ...

Read More

Byte.Equals(Object) Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 165 Views

The Byte.Equals(Object) method in C# returns a value indicating whether this instance is equal to a specified object. This method compares the current byte instance with another object and returns true if they are equal, false otherwise. Syntax Following is the syntax − public override bool Equals (object obj); Parameters obj − An object to compare with this instance, or null. Return Value Returns true if obj is a byte instance and equals the value of this instance; otherwise, false. Example Let us now see an example ...

Read More

Decimal.Remainder() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 319 Views

The Decimal.Remainder() method in C# is used to calculate the remainder after dividing two Decimal values. This method performs the same operation as the modulus operator (%) but is specifically designed for decimal precision calculations. Syntax Following is the syntax − public static decimal Remainder(decimal val1, decimal val2); Parameters val1 − The dividend (the number to be divided). val2 − The divisor (the number by which to divide). Return Value Returns a decimal value representing the remainder after dividing val1 by val2. Division Operation: ...

Read More

How to declare and initialize a list in C#?

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

A List in C# is a generic collection that stores elements in a resizable array. You can declare and initialize a List in several ways, depending on whether you want to add elements immediately or start with an empty collection. Syntax Following is the basic syntax for declaring a List − List listName = new List(); Following is the syntax for initializing a List with values − List listName = new List() { value1, value2, value3 }; Empty List Declaration ...

Read More

Optional property in a C# class

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 6K+ Views

An optional property in a C# class is a property that can have a null value without causing runtime errors. Properties whose CLR types cannot hold null values (like value types) cannot be configured as optional unless they are made nullable using the ? operator. Optional properties are commonly implemented using nullable reference types, default values, or custom attributes to indicate that the property is not required to have a value. Syntax Following is the syntax for declaring nullable properties − public string? PropertyName { get; set; } // Nullable reference type ...

Read More

C# program to get the List of keys from a Dictionary

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

In C#, you can extract all the keys from a Dictionary as a List using the Keys property. This is useful when you need to work with dictionary keys as a separate collection or perform operations like sorting, filtering, or iteration. Syntax Following is the syntax to get keys from a Dictionary − Dictionary dictionary = new Dictionary(); List keys = new List(dictionary.Keys); You can also use LINQ to convert keys to a List − List keys = dictionary.Keys.ToList(); Using Dictionary.Keys Property The Keys property returns a collection of ...

Read More

What are abstract properties in C#?

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

An abstract property in C# is a property declared in an abstract class without implementation. The derived classes must provide the actual implementation of the property accessor (get, set, or both). Abstract properties enforce a contract that ensures all derived classes implement the required property. Abstract properties are useful when you want to define a common structure across related classes but need each class to calculate or store the property value differently. Syntax Following is the syntax for declaring an abstract property − public abstract class ClassName { public abstract DataType PropertyName ...

Read More

Decimal.Round() Method in C#

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

The Decimal.Round() method in C# is used to round a decimal value to the nearest integer or to a specified number of decimal places. This method provides several overloads to handle different rounding scenarios and precision requirements. Syntax The Decimal.Round() method has four main overloads − public static decimal Round(decimal d); public static decimal Round(decimal d, int decimals); public static decimal Round(decimal d, MidpointRounding mode); public static decimal Round(decimal d, int decimals, MidpointRounding mode); Parameters d − The decimal number to be rounded. decimals − The number of decimal ...

Read More

How to declare and initialize constant strings in C#?

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

To declare a constant string in C#, use the const keyword. Constants are immutable values that are set at compile-time and cannot be changed during program execution. Once initialized, attempting to modify a constant will result in a compile-time error. Syntax Following is the syntax for declaring and initializing a constant string − const string constantName = "value"; Constants must be initialized at the time of declaration and the value must be a compile-time constant expression. Key Rules for Constants Constants must be initialized at declaration − you cannot declare ...

Read More

LinkedList in C#

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

The LinkedList class in C# is a doubly-linked list implementation found in the System.Collections.Generic namespace. Unlike arrays or lists, a linked list allows for efficient insertion and removal of elements at any position without the need to shift other elements. Each element in a LinkedList is stored in a node that contains the data and references to both the next and previous nodes. This structure enables fast insertion and deletion operations at the cost of direct indexed access. Syntax Following is the syntax for creating a LinkedList − LinkedList linkedList = new LinkedList(); ...

Read More
Showing 8041–8050 of 25,466 articles
« Prev 1 803 804 805 806 807 2547 Next »
Advertisements