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 693 of 2547
Stack.ToString() Method in C# with examples
The Stack.ToString() method in C# is used to get the string representation of the Stack class object. This method returns the fully qualified type name of the stack instance, not the contents of the stack. To display stack elements, you need to iterate through the collection and call ToString() on individual elements. Syntax Following is the syntax for the Stack.ToString() method − public override string ToString(); Return Value This method returns a string that represents the current Stack object. It returns the type name "System.Collections.Stack". Using ToString() on Stack Elements The ...
Read MoreStringCollection Class in C#
The StringCollection class in C# is a specialized collection that stores strings. It is part of the System.Collections.Specialized namespace and provides methods specifically designed for string operations, making it more efficient than generic collections when working exclusively with strings. Properties Following are the key properties of the StringCollection class − Property Description Count Gets the number of strings contained in the StringCollection. IsReadOnly Gets a value indicating whether the StringCollection is read-only. IsSynchronized Gets a value indicating whether access to the StringCollection is synchronized (thread safe). ...
Read MoreSByte.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 More