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 817 of 2547
Ulong type in C#
The ulong type in C# is a 64-bit unsigned integer that represents the System.UInt64 structure. It can store values from 0 to 18, 446, 744, 073, 709, 551, 615, making it ideal for storing large positive numbers without sign considerations. The ulong keyword is an alias for System.UInt64 and is part of C#'s built-in value types. Since it's unsigned, it cannot store negative values but has twice the positive range compared to long. Syntax Following is the syntax for declaring a ulong variable − ulong variableName = value; You can also use the ...
Read MoreAsEnumerable() in C#
The AsEnumerable() method in C# is used to cast a specific type to its IEnumerable equivalent. It is an extension method from the System.Linq namespace that helps when you need to treat a collection as a basic enumerable sequence, often to force LINQ to Objects behavior over LINQ to SQL or Entity Framework queries. Syntax Following is the syntax for using AsEnumerable() − public static IEnumerable AsEnumerable(this IEnumerable source) Usage example − var enumerable = collection.AsEnumerable(); Parameters source − The sequence to type as IEnumerable. Return ...
Read MoreBigInteger Class in C#
The BigInteger class in C# is designed to handle arbitrarily large integers that exceed the limits of standard integer types. It is part of the System.Numerics namespace and provides support for mathematical operations on very large numbers without overflow. Unlike built-in integer types like int or long, BigInteger can represent integers of any size, limited only by available memory. This makes it ideal for cryptographic calculations, mathematical computations, and scenarios requiring precise arithmetic with large numbers. Syntax The BigInteger structure declaration − [SerializableAttribute] public struct BigInteger : IFormattable, IComparable, IComparable, IEquatable Creating a ...
Read MoreHow do you find the number of dimensions of an array in C#?
To find the number of dimensions of an array in C#, use the Rank property. This property returns an integer representing the total number of dimensions in the array. Syntax Following is the syntax for getting the number of dimensions − int dimensions = arr.Rank; For getting the length of specific dimensions, use the GetLength() method − int lengthOfDimension = arr.GetLength(dimensionIndex); Using Rank Property The Rank property works with single-dimensional, multi-dimensional, and jagged arrays − using System; class Program { static void Main() ...
Read MoreContainsKey in C#
The ContainsKey method in C# is a Dictionary method that checks whether a specified key exists in the dictionary. It returns a boolean value − true if the key is found, false otherwise. This method is essential for safe dictionary operations to avoid exceptions when accessing non-existent keys. Syntax Following is the syntax for the ContainsKey method − public bool ContainsKey(TKey key) Parameters key − The key to locate in the dictionary. This parameter cannot be null for reference types. Return Value Returns true if the dictionary ...
Read MoreC# Linq Intersect Method
The Intersect() method in C# LINQ is used to find common elements between two collections. It returns a new sequence containing elements that exist in both the source collection and the specified collection, with duplicates automatically removed. Syntax Following is the syntax for the Intersect() method − public static IEnumerable Intersect( this IEnumerable first, IEnumerable second ) With a custom equality comparer − public static IEnumerable Intersect( this IEnumerable first, IEnumerable second, ...
Read MoreHow to use the directory class in C#?
The Directory class in C# is used to manipulate the directory structure. It provides static methods to create, move, delete, and query directories without needing to create an instance of the class. The Directory class is part of the System.IO namespace and offers essential functionality for working with file system directories programmatically. Syntax Following is the basic syntax for using Directory class methods − Directory.MethodName(path); Directory.MethodName(path, parameters); Common Directory Class Methods Method Description CreateDirectory(String) Creates all directories and subdirectories in the specified path ...
Read MoreBinary search in C#
The binary search algorithm works on the divide and conquer principle as it keeps dividing the array in half before searching. To search for an element in an array using binary search, the array must be sorted. In the sorted array, we find the middle element and compare it with the element that has to be searched, and based on the comparison, we either search in the left sub-array, right sub-array, or return the middle element. In this article, we are given a sorted array of integers, and our task is to search for the given target element ...
Read MoreWhat is the Capacity property of an ArrayList class in C#?
The Capacity property in the ArrayList class gets or sets the number of elements that the ArrayList can contain. This property represents the internal array size, which is automatically managed by the ArrayList to optimize performance. The capacity is always greater than or equal to the count of elements. When elements are added and the capacity is exceeded, the ArrayList automatically doubles its capacity to accommodate more elements. Syntax Following is the syntax for accessing the Capacity property − arrayListName.Capacity You can also set the capacity explicitly − arrayListName.Capacity = newCapacityValue; ...
Read MoreRetrieving Elements from Collection in C#
Collections in C# provide various ways to retrieve elements. The List collection is one of the most commonly used collections that allows you to access elements by index, retrieve specific elements, or iterate through all elements. Syntax Following is the syntax for accessing elements by index − ElementType element = list[index]; Following is the syntax for using foreach to iterate through all elements − foreach (ElementType item in list) { // process item } Using Index-Based Access You can retrieve elements from a List collection using ...
Read More