Articles on Trending Technologies

Technical articles with clear explanations and examples

SByte.CompareTo() Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 130 Views

The SByte.CompareTo() method in C# is used to compare the current sbyte instance to a specified object or sbyte value and returns an integer that indicates their relative ordering. This method is essential for sorting operations and comparison logic. Syntax The SByte.CompareTo() method has two overloads − public int CompareTo(sbyte value); public int CompareTo(object obj); Parameters value − An 8-bit signed integer to compare with the current instance. obj − An object to compare with the current instance, or null. Return Value The method returns ...

Read More

How to find the shortest distance to a character in a given string using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 447 Views

Finding the shortest distance to a character in a string requires calculating the minimum distance from each position to the nearest occurrence of the target character. This can be efficiently solved using a two-pass approach that scans the string from left to right and then from right to left. The algorithm maintains two arrays to track distances from both directions, then combines them to find the minimum distance at each position. Syntax Following is the method signature for finding shortest distances − public int[] ShortestDistanceToCharacter(string s, char c) Parameters s − ...

Read More

Stack.Push() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 783 Views

The Stack.Push() method in C# is used to insert an object at the top of the Stack. This method follows the Last In, First Out (LIFO) principle, where the most recently pushed element appears first when iterating through the stack. Syntax The syntax is as follows − public virtual void Push (object ob); Parameters ob − The object to push onto the stack. It can be null. Return Value This method does not return any value. It is a void method. Stack.Push() - LIFO Structure ...

Read More

SByte.Equals() Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 127 Views

The SByte.Equals() method in C# is used to return a value indicating whether this instance is equal to a specified object or SByte. The sbyte data type represents an 8-bit signed integer with values ranging from -128 to 127. Syntax The SByte.Equals() method has two overloaded forms − public bool Equals(sbyte ob); public override bool Equals(object ob); Parameters ob (sbyte) − An SByte value to compare to this instance. ob (object) − An object to compare with this instance. Return Value Returns true if the ...

Read More

Check whether the Dictionary has the specified key or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 211 Views

To check whether a Dictionary contains a specified key, C# provides the ContainsKey() method. This method returns true if the key exists in the dictionary, and false otherwise. Syntax Following is the syntax for the ContainsKey() method − public bool ContainsKey(TKey key) Parameters key − The key to locate in the dictionary. Return Value Returns true if the dictionary contains an element with the specified key; otherwise, false. Using ContainsKey() - Key Found The following example demonstrates checking for a key that exists in the ...

Read More

C# BitConverter.ToInt64() Method

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 338 Views

The BitConverter.ToInt64() method in C# is used to convert eight consecutive bytes from a byte array into a 64-bit signed integer (long). This method is particularly useful when working with binary data or when you need to reconstruct numeric values from byte representations. Syntax Following is the syntax for the BitConverter.ToInt64() method − public static long ToInt64(byte[] value, int startIndex); Parameters value − An array of bytes containing the eight bytes to convert. startIndex − The starting position within the byte array from which to begin the conversion. ...

Read More

Check if a SortedList object has a fixed size in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 181 Views

To check if a SortedList object has a fixed size in C#, you can use the IsFixedSize property. This property returns true if the SortedList has a fixed size and cannot dynamically grow or shrink, or false if it can be modified. A regular SortedList object is not fixed in size by default, which means you can add or remove elements dynamically. However, you can create a fixed-size wrapper using methods like SortedList.Synchronized() combined with other collection wrappers. Syntax Following is the syntax for checking if a SortedList has a fixed size − bool isFixed ...

Read More

Get the handle for the Type of a specified object C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 294 Views

To get the handle for the Type of a specified object in C#, you use the Type.GetTypeHandle() method. This method returns a RuntimeTypeHandle structure that represents the type handle, which is a unique identifier for the type in the runtime environment. A type handle is useful for low-level operations and provides a lightweight way to reference types without keeping the full Type object in memory. Syntax Following is the syntax for getting a type handle − RuntimeTypeHandle handle = Type.GetTypeHandle(objectInstance); To convert back from handle to Type − Type type = ...

Read More

Get a collection of values in the StringDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 186 Views

The StringDictionary class in C# provides a collection that maps strings to strings, where keys are case-insensitive. To retrieve values from a StringDictionary, you can access the Values property or iterate through key-value pairs to extract the values. StringDictionary automatically converts all keys to lowercase, making it useful for scenarios where case-insensitive string lookups are required. Syntax Following is the syntax to access values in a StringDictionary − StringDictionary stringDict = new StringDictionary(); ICollection values = stringDict.Values; string value = stringDict[key]; Using Values Property The Values property returns an ICollection containing all ...

Read More

Get the fields of the current Type in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 356 Views

To get the fields of the current Type in C#, you can use the GetFields() method from the System.Reflection namespace. This method allows you to retrieve field information using various BindingFlags to specify which types of fields to include. Reflection in C# provides the ability to inspect and manipulate types, methods, properties, and fields at runtime. The Type.GetFields() method is particularly useful for examining the internal structure of classes. Syntax Following is the basic syntax for getting fields using reflection − Type type = typeof(ClassName); FieldInfo[] fields = type.GetFields(); To get specific types ...

Read More
Showing 9571–9580 of 61,297 articles
« Prev 1 956 957 958 959 960 6130 Next »
Advertisements