AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 169 of 840

Stack.Push() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 784 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 128 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 212 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 339 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 182 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 188 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 359 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

Check if two ArrayList objects are equal in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 414 Views

Checking if two ArrayList objects are equal in C# involves understanding how the Equals() method works. The ArrayList.Equals() method checks for reference equality, not content equality. This means it only returns true if both variables point to the same object in memory. Understanding ArrayList.Equals() Behavior The Equals()

Read More

Add element to HashSet in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 372 Views

The HashSet in C# is a collection that stores unique elements without duplicates. To add elements to a HashSet, you use the Add() method, which returns a boolean value indicating whether the element was successfully added. Syntax Following is the syntax for adding an element to a HashSet − bool result = hashSet.Add(element); Return Value The Add() returns − true if the element was added successfully false if the element already exists in the HashSet Using Add() Method with String HashSet Here's how to ...

Read More
Showing 1681–1690 of 8,392 articles
« Prev 1 167 168 169 170 171 840 Next »
Advertisements