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
810 articles
What is the Keys property of Hashtable class in C#?
The Keys property of the Hashtable class in C# returns an ICollection containing all the keys in the hashtable. This property is useful for iterating through all keys or performing operations on the key collection without accessing the values. Syntax Following is the syntax for accessing the Keys property − public virtual ICollection Keys { get; } Return Value The Keys property returns an ICollection object that contains all the keys in the hashtable. The order of keys is not guaranteed as hashtables do not maintain insertion order. Using Keys Property to ...
Read MoreC# program to find common elements in three arrays using sets
In C#, you can find common elements in three arrays efficiently using HashSet collections. A HashSet provides fast lookups and set operations, making it ideal for finding intersections between collections of data. The HashSet class offers built-in methods like IntersectWith() that can perform set operations directly, eliminating the need for complex loops and comparisons. Syntax Following is the syntax for creating a HashSet from an array − var hashSet = new HashSet(array); Following is the syntax for finding intersection using IntersectWith() − hashSet1.IntersectWith(hashSet2); hashSet1.IntersectWith(hashSet3); Finding ...
Read MoreC# Enum IsDefined Method
The Enum.IsDefined method in C# determines whether a specified value exists within a given enumeration. It returns true if the value is found, either as an integral value or its corresponding string name, and false otherwise. Syntax Following is the syntax for the Enum.IsDefined method − public static bool IsDefined(Type enumType, object value) Parameters enumType − The type of the enumeration to check against. value − The value to look for in the enumeration (can be an integer or string). Return Value Returns true if the specified value exists ...
Read MoreChaining comparison operators in C#
C# supports chaining comparison operators based on operator associativity and precedence. When multiple operators of the same precedence appear in an expression, they are evaluated according to their associativity rules, typically left-to-right. Understanding how comparison operators chain together is crucial for writing correct conditional expressions and avoiding logical errors in your code. Syntax Following is the basic syntax for chaining comparison operators − variable1 == variable2 == variable3 variable1 != variable2 != variable3 The evaluation follows left-to-right associativity − (variable1 == variable2) == variable3 How Operator Chaining Works ...
Read MoreWhat is the difference between public, static and void keywords in C#?
The public, static, and void keywords in C# have specific meanings and are commonly seen together in the Main method of any C# program. Understanding these keywords is essential for C# programming as they control access, memory allocation, and return behavior of methods. The Main method serves as the entry point for all C# programs, defining what a class does when executed. Syntax Following is the typical syntax of the Main method showing all three keywords − public static void Main(string[] args) { // program execution starts here } ...
Read MoreComparing enum members in C#
To compare enum members in C#, you can use the Enum.CompareTo() method or standard comparison operators. Enum comparison is based on the underlying numeric values assigned to each enum member. Syntax Following is the syntax for using CompareTo() method − enumValue1.CompareTo(enumValue2) Following is the syntax for using comparison operators − enumValue1 == enumValue2 // equality enumValue1 > enumValue2 // greater than enumValue1 < enumValue2 // less than Return Value The CompareTo() method returns − Negative value if the first enum is ...
Read MoreC# Program to skip elements from a sequence as long as the specified condition is true
The SkipWhile() method in C# is a LINQ extension method that skips elements from the beginning of a sequence as long as a specified condition remains true. Once the condition becomes false, it returns all remaining elements including the first element that failed the condition. Syntax Following is the syntax for the SkipWhile() method − public static IEnumerable SkipWhile( this IEnumerable source, Func predicate ) Parameters source − The sequence of elements to skip from. predicate − A function to ...
Read MoreWhat is a parameterized constructor in C# programs?
A parameterized constructor in C# is a constructor that accepts parameters to initialize an object with specific values at the time of creation. This allows you to set initial values for the object's fields or properties during instantiation, making object creation more flexible and efficient. Syntax Following is the syntax for declaring a parameterized constructor − public ClassName(dataType parameter1, dataType parameter2) { // initialization code this.field1 = parameter1; this.field2 = parameter2; } To create an object using a parameterized constructor − ClassName objectName ...
Read MoreC# Program to add a node after the given node in a Linked List
A LinkedList in C# is a doubly linked list that allows efficient insertion and removal of elements at any position. The AddAfter() method inserts a new node immediately after a specified existing node in the list. Syntax Following is the syntax for the AddAfter() method − public LinkedListNode AddAfter(LinkedListNode node, T value) Parameters node − The LinkedListNode after which to insert a new node containing value. value − The value to add to the LinkedList. Return Value The method returns the new LinkedListNode containing the ...
Read MoreDynamic Binding in C#
In Dynamic binding, the compiler defers type checking until runtime instead of compile time. This allows you to work with objects whose types are determined dynamically, providing flexibility when dealing with anonymous types, COM objects, or dynamic languages. The dynamic keyword in C# enables late binding, where method calls, property access, and type conversions are resolved at runtime. This is particularly useful for returning anonymous types from methods, since anonymous type names are only visible to the compiler. Syntax Following is the syntax for declaring a dynamic variable − dynamic variableName = value; ...
Read More