Csharp Articles

Page 50 of 196

Set all bits in the BitArray to the specified value in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 151 Views

The BitArray.SetAll() method in C# is used to set all bits in the BitArray to a specified boolean value. This method provides an efficient way to initialize or reset all elements in a BitArray with a single operation, rather than setting each bit individually. Syntax Following is the syntax for the SetAll() method − public void SetAll(bool value) Parameters value: A boolean value (true or false) to assign to all bits in the BitArray. Using SetAll() to Set All Bits to True The following example demonstrates setting all bits in a ...

Read More

Reverse the order of the elements in the entire List or in the specified range in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 343 Views

The List.Reverse() method in C# allows you to reverse the order of elements in a List. You can reverse the entire list or reverse a specific range of elements within the list. Syntax Following is the syntax for reversing the entire list − list.Reverse(); Following is the syntax for reversing a specified range of elements − list.Reverse(int index, int count); Parameters index − The zero-based starting index of the range to reverse. count − The number of elements in the range to reverse. ...

Read More

Check whether the Dictionary contains a specific value or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 502 Views

The Dictionary class in C# provides the ContainsValue() method to check whether a specific value exists in the dictionary. This method returns true if the value is found, otherwise false. Syntax Following is the syntax for the ContainsValue() method − public bool ContainsValue(TValue value); Parameters value − The value to locate in the Dictionary. Return Value Returns true if the Dictionary contains an element with the specified value; otherwise, false. Using ContainsValue() - Value Found The following example demonstrates checking for an existing value in ...

Read More

Get the TypeCode for value type UInt64 in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 202 Views

The GetTypeCode() method in C# returns a TypeCode enumeration value that identifies the specific type of a variable. For UInt64 (unsigned 64-bit integer) values, this method always returns TypeCode.UInt64, regardless of the actual numeric value stored. Syntax Following is the syntax for getting the TypeCode of a UInt64 value − TypeCode typeCode = uintValue.GetTypeCode(); Return Value The method returns TypeCode.UInt64 for all ulong variables, which represents the 64-bit unsigned integer type in the .NET type system. Using GetTypeCode() with UInt64 Values Example using System; public class Demo { ...

Read More

Get all the interfaces implemented or inherited by the current Type in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 611 Views

The Type class in C# provides methods to retrieve all interfaces implemented or inherited by a specific type. The GetInterfaces() method returns an array of all interfaces, while GetInterface() method retrieves a specific interface by name. Syntax Following is the syntax for getting all interfaces implemented by a type − Type[] interfaces = type.GetInterfaces(); Following is the syntax for getting a specific interface by name − Type specificInterface = type.GetInterface("InterfaceName", ignoreCase); Parameters GetInterface(string name) − Returns the interface with the specified name. GetInterface(string name, bool ignoreCase) − Returns ...

Read More

Get the TypeCode for value type UInt32 in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 173 Views

To get the TypeCode for value type UInt32 in C#, you can use the GetTypeCode() method. This method returns a TypeCode enumeration value that represents the data type of the current object. The UInt32 data type represents a 32-bit unsigned integer with values ranging from 0 to 4, 294, 967, 295. When you call GetTypeCode() on any uint variable, it returns TypeCode.UInt32. Syntax Following is the syntax for getting the TypeCode of a UInt32 value − TypeCode typeCode = uintVariable.GetTypeCode(); Return Value The GetTypeCode() method returns TypeCode.UInt32 for all uint variables, regardless ...

Read More

Insert an element into the ArrayList at the specified index in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 379 Views

The ArrayList.Insert() method in C# allows you to insert an element at a specific index position in an ArrayList. This method shifts all existing elements from the specified index to the right, making room for the new element. Syntax Following is the syntax for the Insert() method − arrayList.Insert(index, value); Parameters index − The zero-based index at which the new element should be inserted. value − The object to insert into the ArrayList. ArrayList Insert Operation ...

Read More

Insert an object at the top of the Stack in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 333 Views

To insert an object at the top of the Stack in C#, you use the Push() method. The Stack collection follows the LIFO (Last In, First Out) principle, meaning the most recently added element is always at the top and will be the first one removed. Syntax Following is the syntax for the Push() method − stack.Push(item); Parameters item: The object to insert at the top of the Stack. The value can be null for reference types. How It Works When you call Push(), the new element is added to the ...

Read More

Count the number of key/value pairs in the Hashtable in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 403 Views

In C#, the Hashtable class provides the Count property to determine the number of key/value pairs stored in the collection. This property returns an integer value representing the total count of elements currently in the Hashtable. Syntax Following is the syntax for accessing the Count property − int count = hashtable.Count; Parameters The Count property does not take any parameters. It is a read-only property that returns the current number of key/value pairs in the Hashtable. Return Value The Count property returns an int value representing the total number of key/value ...

Read More

Get the members of the current Type in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 159 Views

In C#, you can use reflection to inspect the members of a type at runtime. The Type.GetMembers() method returns an array of MemberInfo objects representing all public members of a type, including fields, properties, methods, constructors, and events. Syntax Following is the syntax to get all members of a type − Type type = typeof(ClassName); MemberInfo[] members = type.GetMembers(); To filter members using binding flags − MemberInfo[] members = type.GetMembers(BindingFlags.Public | BindingFlags.Instance); Using GetMembers() Without Binding Flags When called without parameters, GetMembers() returns all public members including inherited ones ...

Read More
Showing 491–500 of 1,951 articles
« Prev 1 48 49 50 51 52 196 Next »
Advertisements