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 George John
Page 7 of 79
What are Left Shift and Right Shift Operators (>> and <<) in C#?
The left shift () operators in C# are bitwise operators that shift the bits of a number left or right by a specified number of positions. These operators are commonly used for efficient multiplication and division by powers of 2, as well as for low-level bit manipulation. Syntax Following is the syntax for the left shift operator − result = operand > numberOfPositions; How Left Shift Works The left shift operator (> 3; /* Right shift by 3: 60 / 8 = 7 */ Console.WriteLine("60 >> 3 ...
Read MoreStringWriter vs StringReader in C#?
StringReader and StringWriter are classes in C# that derive from TextReader and TextWriter respectively. They provide convenient ways to read from and write to strings as if they were streams or files. StringWriter is used for writing data into a string buffer, while StringReader is used for reading data from a string. Both classes are particularly useful when working with APIs that expect TextReader or TextWriter objects. StringWriter Class StringWriter implements a TextWriter for writing information to a string. It maintains an internal StringBuilder that accumulates the written content. Syntax StringWriter writer = new ...
Read MoreC# Program to get the name of root directory
Use the RootDirectory property to get the name of the root directory of a drive in C#. This property belongs to the DriveInfo class and returns a DirectoryInfo object representing the root directory. Syntax Following is the syntax for getting the root directory − DriveInfo driveInfo = new DriveInfo("driveLetter"); DirectoryInfo rootDir = driveInfo.RootDirectory; Using DriveInfo.RootDirectory Property First, create a DriveInfo object to specify the drive for which you want the root directory − DriveInfo dInfo = new DriveInfo("C"); Then, the RootDirectory property gives you the root directory − ...
Read MoreC# Linq Select Method
The Select method in C# LINQ is used to transform each element of a collection into a new form. It projects each element of a sequence into a new sequence by applying a transformation function to each element. Syntax Following is the basic syntax for the Select method − public static IEnumerable Select( this IEnumerable source, Func selector ) The overload with index parameter − public static IEnumerable Select( this IEnumerable source, Func selector ) Parameters ...
Read MoreHow to use the ToString() method of array in C#?
The ToString() method in C# returns a string representation of an object. For arrays, the default ToString() method returns the type name rather than the array contents. However, ToString() is commonly used with array properties and methods that return numeric values. Syntax Following is the syntax for using ToString() with array methods − arrayObject.Method().ToString() For converting array elements to strings − array[index].ToString() Using ToString() with Array Properties The ToString() method is useful when converting array properties like bounds and length to string format for display purposes − ...
Read MoreAggregate method in C#
The Aggregate method in C# is a powerful LINQ extension method that performs a sequential operation on all elements in a collection. It applies an accumulator function over a sequence, allowing you to perform custom aggregations like mathematical operations, string concatenations, or complex data transformations. Syntax Following are the main overloads of the Aggregate method − // Basic syntax - uses first element as seed public static TSource Aggregate( this IEnumerable source, Func func ); // With seed value public static TAccumulate Aggregate( ...
Read MoreC# Linq Skip() Method
The Skip() method in C# LINQ is used to skip a specified number of elements from the beginning of a sequence and return the remaining elements. This method is particularly useful when you need to bypass certain elements in a collection before processing the rest. Syntax Following is the syntax for the Skip() method − public static IEnumerable Skip( this IEnumerable source, int count ) Parameters source − The sequence to return elements from. count − The number of elements ...
Read MoreHow to define multiline String Literal in C#?
A multiline string literal in C# allows you to define strings that span multiple lines while preserving the line breaks and formatting. This is achieved using the @ symbol prefix, which creates a verbatim string literal. Syntax Following is the syntax for defining a multiline string literal − string variableName = @"Line 1 Line 2 Line 3"; The @ symbol tells the compiler to treat the string literally, preserving all whitespace, line breaks, and special characters without requiring escape sequences. Using Verbatim String Literals Let's say you want to create a string ...
Read MoreC# Program to find the sum of a sequence
A sequence in C# is a collection of elements that can be processed using LINQ methods. To find the sum of a sequence, you can use several approaches including the Sum() method from LINQ, which provides a simple and efficient way to calculate the total. The most common approach is using the LINQ Sum() method, which can be applied to any IEnumerable collection. Syntax Following is the syntax for using the Sum() method − // For numeric collections collection.Sum(); // With selector function collection.Sum(x => x.Property); Using LINQ Sum() Method The ...
Read MoreWhat are extender provider components in C#?
An extender provider in C# is a component that can extend other controls by providing additional properties to them at design time. The most common example is the ToolTip component, which adds tooltip functionality to other controls on a form. When you add a ToolTip component to a form, it automatically provides a new property (like "ToolTip on toolTip1") to every other control on the form. This allows you to set tooltip text for each control without directly modifying the control itself. How Extender Providers Work Extender providers implement the IExtenderProvider interface and use special naming conventions ...
Read More