Csharp Articles

Page 16 of 196

C# Object.GetType() Method with Examples

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

The Object.GetType() method in C# is used to get the runtime type of the current instance. This method is inherited by all types in C# since every type derives from Object. It returns a Type object that contains metadata about the type. Syntax Following is the syntax for the GetType() method − public Type GetType(); Return Value The method returns a Type object that represents the exact runtime type of the current instance. Using GetType() with Built-in Types The GetType() method can be called on any object to determine its type ...

Read More

C# Queue.TrimExcess() Method with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 368 Views

The Queue.TrimExcess() method in C# is used to set the capacity to the actual number of elements in the Queue, if that number is less than 90 percent of current capacity. This method helps optimize memory usage by reducing the internal array size when the queue has significantly fewer elements than its current capacity. Syntax public void TrimExcess(); Parameters: This method takes no parameters. Return Value: This method does not return any value (void). How It Works The TrimExcess() method only reduces capacity when the current element count is less than 90% ...

Read More

C# String Operators

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 640 Views

C# provides several string operators that allow you to perform operations and comparisons on strings. The primary string operators include equality (==), inequality (!=), and the concatenation operator (+). These operators make string manipulation and comparison straightforward and intuitive. Syntax Following is the syntax for string comparison operators − bool result = string1 == string2; // Equality bool result = string1 != string2; // Inequality string result = string1 + string2; // Concatenation String Equality Operator (==) The equality operator checks if two strings have the same content. It performs a ...

Read More

C# BitConverter.ToUInt32() Method

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 431 Views

The BitConverter.ToUInt32() method in C# converts four consecutive bytes from a byte array into a 32-bit unsigned integer. This method reads bytes in little-endian format, where the least significant byte comes first. Syntax public static uint ToUInt32(byte[] value, int startIndex); Parameters value − The byte array containing the data to convert. startIndex − The starting position within the byte array (must be between 0 and array length minus 4). Return Value Returns a 32-bit unsigned integer (uint) formed by four bytes beginning at startIndex. Little-Endian ...

Read More

TimeSpan.FromDays() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 759 Views

The TimeSpan.FromDays() method in C# is used to create a TimeSpan object that represents a specified number of days. This static method is particularly useful when you need to work with time intervals measured in days and want to convert them to a TimeSpan for calculations or comparisons. Syntax Following is the syntax for the TimeSpan.FromDays() method − public static TimeSpan FromDays(double value); Parameters value: A double-precision floating-point number representing the number of days. The value can be positive, negative, or zero, and is accurate to the nearest millisecond. Return Value ...

Read More

Double.IsNaN() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 776 Views

The Double.IsNaN() method in C# is used to determine whether a specified double value is "Not a Number" (NaN). This static method returns true if the value represents NaN, and false otherwise. NaN values typically result from invalid mathematical operations like dividing zero by zero. Syntax Following is the syntax for the Double.IsNaN() method − public static bool IsNaN(double val); Parameters val − A double-precision floating-point number to test. Return Value Returns true if the value is NaN; otherwise, false. Double.IsNaN() Results ...

Read More

Stack.Equals() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 376 Views

The Stack.Equals() method in C# is used to check whether a Stack class object is equal to another object or not. This method performs reference equality, not content equality, meaning it returns true only if both variables reference the same Stack object in memory. Syntax Following is the syntax for the Stack.Equals() method − public virtual bool Equals(object obj); Parameters obj − The object to compare with the current Stack instance. Return Value Returns true if the specified object is the same instance as the current Stack; otherwise, false. ...

Read More

Stack.GetEnumerator() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 162 Views

The Stack.GetEnumerator() method in C# returns an IEnumerator that allows you to iterate through the elements of a Stack collection. This method provides a way to manually control the iteration process using the enumerator pattern, as an alternative to using 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 be used to iterate through the Stack elements. The enumerator starts before the first element and advances using MoveNext(), with the current element accessed via the Current ...

Read More

TimeSpan.FromHours() Method in C#

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

The TimeSpan.FromHours() method in C# is used to create a TimeSpan object that represents a specified number of hours. This static method is accurate to the nearest millisecond and provides a convenient way to create time spans based on hour values. Syntax Following is the syntax for the TimeSpan.FromHours() method − public static TimeSpan FromHours(double value); Parameters value − A double that represents the number of hours. The value can be positive or negative and is accurate to the nearest millisecond. Return Value This method returns a ...

Read More

TimeSpan.Subtract() Method in C#

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

The TimeSpan.Subtract() method in C# returns a new TimeSpan object whose value is the difference between the current instance and the specified TimeSpan object. This method is useful for calculating time differences in applications dealing with durations and intervals. Syntax Following is the syntax for the TimeSpan.Subtract() method − public TimeSpan Subtract(TimeSpan span); Parameters span − The TimeSpan object to subtract from the current instance. Return Value Returns a new TimeSpan object that represents the time interval difference. If the subtracted value is greater than the current ...

Read More
Showing 151–160 of 1,951 articles
« Prev 1 14 15 16 17 18 196 Next »
Advertisements