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
Articles on Trending Technologies
Technical articles with clear explanations and examples
SByte.CompareTo() Method in C# with Examples
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 MoreHow to find the shortest distance to a character in a given string using C#?
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 MoreStack.Push() Method in C#
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 MoreSByte.Equals() Method in C# with Examples
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 MoreCheck whether the Dictionary has the specified key or not in C#
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 MoreC# BitConverter.ToInt64() Method
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 MoreCheck if a SortedList object has a fixed size in C#
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 MoreGet the handle for the Type of a specified object C#
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 MoreGet a collection of values in the StringDictionary in C#
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 MoreGet the fields of the current Type in C#
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