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 72 of 2547
Queue.Count Property in C#
The Queue.Count property in C# is a read-only property that returns the number of elements currently stored in the Queue collection. This property provides an efficient way to check the size of the queue without needing to iterate through all elements. Syntax The syntax for the Queue.Count property is as follows − public virtual int Count { get; } Return Value The Count property returns an int value representing the total number of elements in the Queue. If the queue is empty, it returns 0. Using Count with Queue Operations The ...
Read MoreHow do I copy items from list to list without foreach in C#?
There are several efficient methods to copy items from one list to another in C# without using a foreach loop. These methods provide different approaches depending on whether you need a complete copy, partial copy, or want to append items to an existing list. Using List Constructor The most straightforward method is to use the List constructor that accepts an IEnumerable parameter. This creates a new list with all elements from the source list − using System; using System.Collections.Generic; class Program { public static void Main() { ...
Read MoreHow to implement Open Closed principle using C#?
The Open Closed Principle (OCP) is one of the five SOLID principles of object-oriented programming. It states that software entities like classes, modules and functions should be open for extension but closed for modifications. Definition The Open Closed Principle states that the design and writing of code should be done in a way that new functionality can be added with minimum changes to existing code. The design should allow adding new functionality through new classes while keeping existing code unchanged as much as possible. Open Closed Principle OPEN ...
Read MoreCreating an Index From the Specified Index at the Start of a Collection in C#
In C#, manipulating collections is a frequent operation, with indexing being a crucial part of this process. The Index struct, introduced in C# 8.0, provides a powerful way to create indices that can represent positions from the start or end of a collection. This article will guide you through creating and using indices from specified positions at the start of collections in C#. Syntax Following is the syntax for creating an Index from the start of a collection − Index index = new Index(value, fromEnd: false); // OR using implicit conversion Index index = value; ...
Read MoreQueue.Dequeue Method in C#
The Queue.Dequeue() method in C# is used to remove and return the object at the beginning of the Queue. This method follows the FIFO (First In, First Out) principle, where the first element added to the queue is the first one to be removed. Syntax Following is the syntax for the Dequeue() method − public T Dequeue(); Return Value The method returns the object that is removed from the beginning of the Queue. If the queue is empty, it throws an InvalidOperationException. Queue.Dequeue() Operation ...
Read MoreRemove all the strings from the StringCollection in C#
The StringCollection class in C# provides the Clear() method to remove all strings from the collection at once. This method is part of the System.Collections.Specialized namespace and is useful when you need to empty the entire collection efficiently. Syntax Following is the syntax for the Clear() method − stringCollection.Clear(); Parameters The Clear() method does not take any parameters. Return Value The Clear() method does not return any value. It has a return type of void. StringCollection.Clear() Process Before Clear() ...
Read MoreHow to calculate the total number of items defined in an enum in C#?
An enum is a special value type that represents a group of named constants. When working with enums, you often need to know how many items are defined in the enum. C# provides several methods to calculate the total count of enum items. Syntax Following are the main approaches to get the total count of enum items − // Using Enum.GetNames() int count = Enum.GetNames(typeof(EnumName)).Length; // Using Enum.GetValues() int count = Enum.GetValues(typeof(EnumName)).Length; Using Enum.GetNames() Method The Enum.GetNames() method returns an array of string names for all enum values. The Length property gives ...
Read MoreCross Join in LINQ
Language Integrated Query (LINQ) is a powerful tool in C# for data manipulation, allowing for efficient and expressive data access and manipulation. One of the operations you can perform with LINQ is the cross join operation, which creates a Cartesian product between two data sources. Understanding Cross Join Cross join, also known as Cartesian product, is a type of join operation that matches each row of the first table with every row of the second table. If the first table has n rows and the second table has m rows, the result is a table with n×m rows. ...
Read MoreHow to find the Number of CPU Cores in C#?
Finding the number of CPU cores in C# involves understanding different types of processor information. There are several ways to get processor details − Physical processors − The actual number of CPU sockets CPU cores − The number of physical processing units Logical processors − The number of threads the CPU can handle simultaneously These values can differ significantly. For example, a machine with 2 dual-core hyper-threading-enabled processors has 2 physical processors, 4 cores, and 8 logical processors. CPU Architecture Example Physical CPU 1 ...
Read MoreHow to set the alignment of Check Mark in CheckBox in C#?
In a graphical user interface, a CheckBox control in C# enables users to pick a true/false or yes/no choice. The check mark in a CheckBox control is normally aligned to the left, but you can customize its position using the CheckAlign property. Syntax The syntax to change the alignment of the check mark is − checkBox1.CheckAlign = ContentAlignment.MiddleRight; The CheckAlign property accepts values from the ContentAlignment enumeration − MiddleLeft − Align the check mark to the left edge of the control (default). MiddleRight − Align the check mark to ...
Read More