Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 48 of 2547
Single.IsInfinity() Method in C# with Example
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 MoreCheck if SortedDictionary contains the specified key or not in C#
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 MoreGet the HashCode for the current UInt64 instance in C#
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 MoreHow many destructors can we have in one class in C#?
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 MoreWhat is Liskov Substitution principle and how to implement in C#?
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 MoreQueue.GetEnumerator() Method in C#
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 MoreAdding an element to the List in C#
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 MoreHow to explicitly call base class constructor from child class in C#?
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 MoreHow to get the name of the current executable in C#?
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 MoreByte Struct in C#
The byte struct in C# represents an 8-bit unsigned integer that can store values from 0 to 255. It is one of the fundamental value types in .NET and provides various methods for comparison, conversion, and formatting operations. Syntax Following is the syntax for declaring and initializing a byte variable − byte variableName = value; // value must be between 0 and 255 Fields The byte struct provides two important constant fields − Field Description Value MaxValue Represents the largest possible value of a ...
Read More