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 4 of 81
C# 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 MoreTime Functions in C#
The DateTime structure in C# provides numerous methods and properties for working with dates and times. These time functions allow you to manipulate DateTime instances by adding or subtracting specific time intervals, extracting time components, and performing various time-related operations. Time functions in C# are essential for applications that need to handle scheduling, logging, time calculations, and date arithmetic operations. Common Time Functions The following table shows the most commonly used time manipulation methods in the DateTime class − Method Description AddDays(Double) Returns a new DateTime that adds the ...
Read MoreWhat is index-based I/O BitArray collection in C#?
The BitArray class in C# manages a compact array of bit values represented as Boolean values, where true indicates the bit is on (1) and false indicates the bit is off (0). It is part of the System.Collections namespace and provides an efficient way to store and manipulate bits. BitArray is particularly useful for scenarios requiring bitwise operations, boolean flags, or when memory efficiency is crucial since it stores bits compactly rather than using full bytes for each boolean value. Syntax Following is the syntax for creating a BitArray − BitArray bitArray = new BitArray(size); ...
Read MoreC# program to remove an item from Set
A HashSet in C# is a collection that stores unique elements and provides efficient methods to add, remove, and search items. To remove items from a HashSet, you can use methods like Remove(), RemoveWhere(), or Clear(). Syntax Following are the common methods to remove items from a HashSet − // Remove a specific item bool removed = hashSet.Remove(item); // Remove items based on a condition int count = hashSet.RemoveWhere(predicate); // Remove all items hashSet.Clear(); Using Remove() Method The Remove() method removes a specific item from the HashSet and returns true if ...
Read MoreC# DateTime Max Value
The DateTime.MaxValue property in C# returns the maximum possible value for a DateTime object. This represents the largest date and time that can be stored in a DateTime structure, which is December 31, 9999 at 11:59:59.9999999 PM. This property is useful when you need to initialize a DateTime variable with the highest possible value, compare dates to find the maximum, or set upper bounds in date range validations. Syntax Following is the syntax for accessing the maximum DateTime value − DateTime maxValue = DateTime.MaxValue; DateTime MaxValue Example The following example demonstrates how ...
Read MoreGenerics vs non-generics in C#
There are two main types of collections in C#: generic collections and non-generic collections. The primary difference lies in type safety, performance, and how they handle different data types. Generic Collections Generic collections are type-safe and hold elements of the same data type. They provide better performance as they avoid boxing and unboxing operations for value types. Key Features Type Safety: Compile-time type checking prevents runtime errors Better Performance: No boxing/unboxing for value types IntelliSense Support: Better code completion and error detection Common Generic Collections List − Dynamic array of type ...
Read MoreC# Console BufferHeight Property
The Console.BufferHeight property in C# gets or sets the height of the buffer area in rows. The buffer height represents the maximum number of text rows that can be stored in the console's internal buffer before older lines are discarded. This property is particularly useful when you need to control how much output history the console retains or when working with console applications that produce large amounts of output. Syntax Following is the syntax for using the BufferHeight property − // Get buffer height int height = Console.BufferHeight; // Set buffer height Console.BufferHeight = ...
Read More