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 by Chandu yadav
Page 9 of 81
What is the Count property of SortedList class in C#?
The Count property of the SortedList class in C# returns the number of key-value pairs stored in the collection. This read-only property is useful for determining the size of the sorted list and performing operations that depend on the collection's current size. Syntax Following is the syntax for accessing the Count property − int count = sortedList.Count; Return Value The Count property returns an int value representing the total number of key-value pairs currently stored in the SortedList. Example The following example demonstrates how to use the Count property to get ...
Read MoreWhat is a non-static class in C#?
A non-static class in C# is a regular class that can be instantiated using the new keyword. Unlike static classes, non-static classes allow you to create multiple objects (instances) and can contain both instance members and static members. Non-static classes are the default type of class in C# and form the foundation of object-oriented programming, enabling encapsulation, inheritance, and polymorphism. Syntax Following is the syntax for declaring a non-static class − public class ClassName { // instance fields // static fields // instance ...
Read MoreImplicit conversion from 16-bit unsigned integer (ushort) to Decimal in C#
ushort represents a 16-bit unsigned integer in C# with a range from 0 to 65, 535. C# allows implicit conversion from ushort to decimal because this conversion is always safe and does not result in data loss. The decimal type can accommodate the entire range of ushort values without precision loss, making implicit conversion possible. Syntax Following is the syntax for implicit conversion from ushort to decimal − ushort ushortValue = value; decimal decimalValue = ushortValue; // implicit conversion How It Works The conversion happens automatically without requiring explicit casting or ...
Read MoreWhat are reference data types in C#?
The reference data types in C# do not store the actual data directly in a variable, but instead contain a reference (or pointer) to the memory location where the data is stored. When you assign a reference type variable to another variable, both variables point to the same object in memory. In C#, the following are the built-in reference types − Object Type The object type is the ultimate base class for all data types in C# Common Type System (CTS). Object variables can be assigned values of any other types, whether value types, reference types, predefined, ...
Read MoreGet the drive format in C#
The DriveFormat property in C# is used to get the file system format of a drive. It returns a string representing the format type such as NTFS, FAT32, or exFAT for Windows systems. Syntax Following is the syntax for using the DriveFormat property − DriveInfo driveInfo = new DriveInfo(driveLetter); string format = driveInfo.DriveFormat; Parameters driveLetter − A string representing the drive letter (e.g., "C", "D", "E"). Return Value The DriveFormat property returns a string containing the name of the file system, such as "NTFS", "FAT32", or "exFAT". ...
Read MoreC# Queryable SequenceEqual() Method
The SequenceEqual() method in C# is used to determine whether two sequences are equal by comparing elements in the same position. This method returns true if both sequences contain the same elements in the same order, otherwise it returns false. The method is part of the System.Linq namespace and can be used with IQueryable collections to perform element-by-element comparison. Syntax Following is the syntax for the SequenceEqual() method − public static bool SequenceEqual( this IQueryable source1, IEnumerable source2 ) With custom comparer − ...
Read MoreWhy is the Main() method use in C# static?
The Main() method in C# is declared as static because it serves as the entry point of the program and must be callable without creating an instance of the class. When a C# program starts, no objects exist yet, so the runtime needs a way to begin execution without instantiation. Why Main() Must Be Static The static keyword allows the method to be called directly on the class rather than on an instance. Since the program hasn't created any objects when it starts, the Main() method must be accessible without instantiation − Program ...
Read MoreAll Method in C#
The All() extension method is part of the System.Linq namespace. Using this method, you can check whether all the elements in a collection match a certain condition or not. It returns true if all elements satisfy the condition, otherwise false. Syntax Following is the syntax for the All() method − bool result = collection.All(predicate); Parameters predicate − A function to test each element for a condition. It takes an element as input and returns a boolean value. Return Value The All() method returns true if all elements ...
Read MoreC# Numeric ("N") Format Specifier
The numeric (N) format specifier converts a number to a string with thousands separators and decimal places. It follows the pattern -d, ddd, ddd.ddd… where the minus sign appears for negative numbers, digits are grouped with commas, and decimal places are included. Syntax Following is the syntax for using the numeric format specifier − number.ToString("N") // Default 2 decimal places number.ToString("N0") // No decimal places number.ToString("Nn") ...
Read MoreHow do we access elements from the two-dimensional array in C#?
A two-dimensional array in C# can be thought of as a table structure with rows and columns. Elements are accessed using two indices: the row index and the column index, separated by a comma within square brackets. Syntax Following is the syntax for accessing elements from a two-dimensional array − dataType value = arrayName[rowIndex, columnIndex]; Following is the syntax for assigning values to elements − arrayName[rowIndex, columnIndex] = value; 2D Array Structure Columns [0] [1] [2] ...
Read More