How to get a path to the desktop for current user in C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

6K+ Views

The desktop path of the current user can be fetched using Environment.GetFolderPath() with the Environment.SpecialFolder.Desktop enumeration. This method provides a reliable, cross-platform way to access special system folders. Syntax Following is the syntax for getting the desktop path − string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); The Environment.GetFolderPath() method takes an Environment.SpecialFolder enumeration value and returns the path to that special folder as a string. Parameters The method accepts the following parameter − folder − An Environment.SpecialFolder enumeration value that identifies the special folder whose path is to be retrieved. Return ... Read More

Single.IsInfinity() Method in C# with Example

AmitDiwan
Updated on 17-Mar-2026 07:04:36

205 Views

The Single.IsInfinity() method in C# is used to determine whether a single-precision floating-point number represents positive or negative infinity. This method is particularly useful when performing mathematical operations that might result in infinite values, such as division by zero. Syntax Following is the syntax for the Single.IsInfinity() method − public static bool IsInfinity(float val); Parameters val − A single-precision floating-point number to be tested for infinity. Return Value The method returns true if the specified value evaluates to positive or negative infinity; otherwise, false. Single.IsInfinity() Method ... Read More

Check if SortedDictionary contains the specified key or not in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

202 Views

To check if a SortedDictionary contains a specified key, C# provides the ContainsKey() method. This method returns true if the key exists in the dictionary, otherwise false. The SortedDictionary maintains its elements in sorted order by key, making key lookups efficient with O(log n) time complexity. Syntax Following is the syntax for the ContainsKey() method − public bool ContainsKey(TKey key) Parameters key − The key to locate in the SortedDictionary. Return Value Returns true if the SortedDictionary contains an element with the specified key; otherwise, false. Using ContainsKey() ... Read More

Get the HashCode for the current UInt64 instance in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

207 Views

The GetHashCode() method in C# returns a hash code for the current UInt64 instance. Hash codes are primarily used in hash tables and dictionaries to quickly locate objects. For UInt64 values, the hash code is typically derived from the numeric value itself. Syntax Following is the syntax for getting the hash code of a UInt64 instance − public override int GetHashCode() Return Value The method returns a 32-bit signed integer hash code representing the current UInt64 value. Using GetHashCode() with Small Values For smaller UInt64 values that fit within the range ... Read More

How many destructors can we have in one class in C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

539 Views

In C#, a destructor is a special method used to clean up resources when an object is destroyed. The answer to how many destructors a class can have is simple: only one destructor per class. Destructors are also called finalizers because they are automatically converted to Finalize() method calls by the compiler. Syntax Following is the syntax for declaring a destructor − class ClassName { ~ClassName() { // cleanup code } } Properties of Destructors Destructors do not ... Read More

What is Liskov Substitution principle and how to implement in C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

425 Views

The Liskov Substitution Principle (LSP) is one of the five SOLID principles in object-oriented programming. It states that derived types must be completely substitutable for their base types without altering the correctness of the program. In other words, objects of a superclass should be replaceable with objects of its subclasses without breaking the application. Definition According to LSP, we should be able to treat a child class as though it were the parent class. This means that all derived classes should retain the functionality of their parent class and cannot replace any functionality the parent provides in a ... Read More

Queue.GetEnumerator() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

183 Views

The Queue.GetEnumerator() method in C# returns an IEnumerator object that allows you to iterate through the elements of a Queue in FIFO (First In, First Out) order. This method is essential for implementing custom iteration logic or using the Queue in foreach loops. Syntax Following is the syntax for the GetEnumerator() method − public virtual System.Collections.IEnumerator GetEnumerator(); Return Value The method returns an IEnumerator object that can iterate through the Queue elements from the front to the rear. Using GetEnumerator() with While Loop The most common way to use GetEnumerator() is ... Read More

Adding an element to the List in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

321 Views

The List class in C# provides the Add() method to add elements to the end of the list. This method is part of the System.Collections.Generic namespace and allows you to dynamically grow the list by appending new elements. Syntax Following is the syntax for adding an element to a List − list.Add(element); Parameters element − The object to be added to the end of the List. The value can be null for reference types. Adding String Elements to List using System; using System.Collections.Generic; public class Demo { ... Read More

How to explicitly call base class constructor from child class in C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

1K+ Views

The base keyword in C# is used to explicitly call a constructor from the parent class when creating an instance of a derived class. This is essential when the base class doesn't have a parameterless constructor or when you need to pass specific values to initialize the base class properly. By default, C# automatically calls the parameterless constructor of the base class. However, when the base class only has parameterized constructors, you must explicitly specify which constructor to call using the base keyword. Syntax Following is the syntax for calling a base class constructor from a derived ... Read More

How to get the name of the current executable in C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

5K+ Views

There are several ways to get the name of the current executable in C#. Each method provides different levels of detail about the executable file, from just the name to the full path. Using System.AppDomain The AppDomain.CurrentDomain.FriendlyName property provides the name of the current application domain, which typically corresponds to the executable filename including its extension. Example using System; namespace DemoApplication { public class Program { public static void Main() { ... Read More

Advertisements