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 on Trending Technologies
Technical articles with clear explanations and examples
KeyValuePair in C#
The KeyValuePair struct in C# stores a pair of values in a single object, where one value acts as the key and the other as the value. It is commonly used in collections like List and as the element type in dictionaries. KeyValuePair is particularly useful when you need to associate two related pieces of data together without creating a custom class or when working with dictionary enumerations. Syntax Following is the syntax for creating a KeyValuePair − KeyValuePair pair = new KeyValuePair(key, value); Following is the syntax for accessing key and value ...
Read MoreHow to use the GetLowerBound method of array class in C#
The GetLowerBound() method of the Array class in C# returns the lower bound of the specified dimension in an array. For most arrays in C#, the lower bound is typically 0, but this method becomes useful when working with arrays that have custom bounds or multi-dimensional arrays. Syntax Following is the syntax for the GetLowerBound() method − public int GetLowerBound(int dimension); Parameters dimension − A zero-based dimension of the array whose lower bound needs to be found. Return Value Returns an integer representing the lower bound of the specified ...
Read MoreC# program to check if binary representation is palindrome
A binary palindrome is a number whose binary representation reads the same forwards and backwards. To check if a number's binary representation is a palindrome, we need to reverse its binary form and compare it with the original. For example, the number 5 has binary representation 101, which reads the same forwards and backwards, making it a binary palindrome. How It Works The algorithm uses bitwise operations to reverse the binary representation − Left shift (=) moves bits to the right, effectively dividing by 2 AND operation (&) checks if the least ...
Read MoreWhat is the Count property of BitArray class in C#?
The Count property of the BitArray class in C# returns the total number of elements (bits) in the BitArray. This is a read-only property that gives you the size of the BitArray, which is determined when the BitArray is created. Syntax Following is the syntax for accessing the Count property − int count = bitArray.Count; Return Value The Count property returns an int value representing the number of bits in the BitArray. Using Count Property with BitArray Let us first create a BitArray and then use the Count property to get ...
Read MoreWhat is the difference between overriding and shadowing in C#?
In C#, overriding and shadowing (also known as method hiding) are two different mechanisms for modifying inherited behavior. Overriding uses the virtual/override keywords to provide specific implementations of base class methods, while shadowing uses the new keyword to hide base class members entirely. Syntax Following is the syntax for method overriding − // Base class public virtual void MethodName() { } // Derived class public override void MethodName() { } Following is the syntax for method shadowing/hiding − // Base class public void MethodName() { } // Derived class public ...
Read MoreAsQueryable() in C#
The AsQueryable() method in C# is used to convert an IEnumerable collection into an IQueryable interface. This conversion enables LINQ query providers to translate queries into optimized database queries or other queryable data sources. The key difference is that IEnumerable executes queries in-memory using LINQ to Objects, while IQueryable can be translated into expression trees for remote execution, such as database queries. Syntax Following is the syntax for using AsQueryable() method − IQueryable queryable = collection.AsQueryable(); The method returns an IQueryable that represents the original collection as a queryable data source. Using ...
Read MoreHow to sort a list in C#?
Sorting a list in C# can be accomplished using several methods. The List class provides the Sort() method for in-place sorting, while LINQ offers additional sorting capabilities. This article demonstrates various approaches to sort lists in ascending and descending order. Syntax Following is the syntax for the basic Sort() method − list.Sort(); Following is the syntax for sorting with a custom comparer − list.Sort((x, y) => y.CompareTo(x)); // descending order Using List.Sort() Method The Sort() method sorts the elements in the entire list using the default comparer for the ...
Read MoreMath.Round() Method in C#
The Math.Round() method in C# rounds a value to the nearest integer or to the specified number of fractional digits. This method provides several overloads to handle different data types and rounding scenarios. Syntax The following are the primary syntax forms of Math.Round() − Math.Round(Double) Math.Round(Double, Int32) Math.Round(Double, Int32, MidpointRounding) Math.Round(Double, MidpointRounding) Math.Round(Decimal) Math.Round(Decimal, Int32) Math.Round(Decimal, Int32, MidpointRounding) Math.Round(Decimal, MidpointRounding) Parameters value − The decimal or double number to be rounded. digits − The number of fractional digits in the return value. mode − Specification for how to round value if it ...
Read MoreC# program to check if there are K consecutive 1's in a binary number
A C# program to check if there are K consecutive 1's in a binary number involves counting the longest sequence of consecutive 1's and comparing it with the required count K. This is useful for binary pattern analysis and digital signal processing applications. Approach The algorithm iterates through the binary array, maintaining a counter for consecutive 1's. When a 0 is encountered, the counter resets. The maximum consecutive count is tracked using Math.Max() method. Using Boolean Array Representation A binary number can be represented as a boolean array where true represents 1 and false represents 0 ...
Read MoreWhat is the Count property of Hashtable class in C#?
The Count property of the Hashtable class in C# returns the total number of key-value pairs stored in the hashtable. It is a read-only property that provides an efficient way to determine the size of the collection. Syntax Following is the syntax for using the Count property − int count = hashtable.Count; Return Value The Count property returns an int value representing the number of key-value pairs currently stored in the hashtable. Using Count Property with Basic Operations The following example demonstrates how to use the Count property to track the ...
Read More