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
Csharp Articles
Page 156 of 196
Implicit conversion from 16-bit unsigned integer (ushort) to Decimal in C#
ushort represents a 16-bit unsigned integer in C# with a range from 0 to 65, 535. C# allows implicit conversion from ushort to decimal because this conversion is always safe and does not result in data loss. The decimal type can accommodate the entire range of ushort values without precision loss, making implicit conversion possible. Syntax Following is the syntax for implicit conversion from ushort to decimal − ushort ushortValue = value; decimal decimalValue = ushortValue; // implicit conversion How It Works The conversion happens automatically without requiring explicit casting or ...
Read MoreFull Date Long Time ("F") Format Specifier in C#
The Full Date Long Time ("F") format specifier in C# displays a complete date and time representation in a long format. This format specifier uses the current culture's DateTimeFormatInfo.FullDateTimePattern property to determine the exact format string. The "F" specifier provides the most comprehensive date and time display, showing the full day name, complete date, and precise time including seconds. Syntax Following is the syntax for using the "F" format specifier − DateTime.ToString("F") DateTime.ToString("F", CultureInfo) The default custom format string for "F" is − dddd, dd MMMM yyyy HH:mm:ss Using ...
Read MoreC# Linq Reverse Method
The LINQ Reverse() method in C# is used to reverse the order of elements in a sequence. It returns a new sequence with elements in reverse order without modifying the original collection. Syntax Following is the syntax for the LINQ Reverse() method − public static IEnumerable Reverse( this IEnumerable source ) Parameters source: The sequence of values to reverse. It must implement IEnumerable. Return Value The Reverse() method returns an IEnumerable whose elements correspond to those of the input sequence in reverse order. ...
Read MoreC# Console BufferWidth Property
The Console.BufferWidth property in C# gets or sets the width of the buffer area in columns. The buffer area is the region of memory that stores console output before it's displayed on the screen. This property is particularly useful when you need to control the console display width programmatically. Syntax Following is the syntax for getting the buffer width − int width = Console.BufferWidth; Following is the syntax for setting the buffer width − Console.BufferWidth = value; Return Value The property returns an int representing the width of the ...
Read MoreC# Program to find the cube of elements in a list
This program demonstrates how to find the cube of each element in a list using the Select() method with a lambda expression. The Select() method transforms each element in the collection by applying a specified function. Syntax Following is the syntax for using Select() method with lambda expression − collection.Select(x => expression) For calculating the cube of each element − list.Select(x => x * x * x) Using Select() Method to Calculate Cube The Select() method applies a transformation function to each element in the list. In this case, ...
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 MoreC# Linq SelectMany Method
The SelectMany method in C# LINQ is used to flatten collections of collections into a single sequence. It projects each element of a sequence to an IEnumerable and then flattens the resulting sequences into one sequence. Syntax Following is the basic syntax for SelectMany method − public static IEnumerable SelectMany( this IEnumerable source, Func selector ) Parameters source − The input sequence to transform. selector − A function that transforms each element into a collection. Return Value Returns an IEnumerable whose ...
Read MoreC# Queryable SequenceEqual() Method
The SequenceEqual() method in C# is used to determine whether two sequences are equal by comparing elements in the same position. This method returns true if both sequences contain the same elements in the same order, otherwise it returns false. The method is part of the System.Linq namespace and can be used with IQueryable collections to perform element-by-element comparison. Syntax Following is the syntax for the SequenceEqual() method − public static bool SequenceEqual( this IQueryable source1, IEnumerable source2 ) With custom comparer − ...
Read MoreC# Program to read all the lines one by one in a file
The File.ReadAllLines() method in C# reads all lines from a file and returns them as a string array. This method is useful when you need to process a file line by line or access specific lines by their index. Syntax Following is the syntax for File.ReadAllLines() method − string[] lines = File.ReadAllLines(filePath); Parameters filePath − The path to the file to be read (string) Return Value Returns a string[] array containing all lines from the file. Each element represents one line from the file. Using ReadAllLines() to Read ...
Read MoreC# Single() Method
The Single() method in C# returns the only element of a sequence. It throws an exception if the sequence is empty or contains more than one element, making it useful when you expect exactly one element. The Single() method is available in both LINQ to Objects and LINQ to Entities through the System.Linq namespace. Syntax Following is the syntax for the Single() method − public static TSource Single(this IEnumerable source); public static TSource Single(this IEnumerable source, Func predicate); Parameters source − The IEnumerable to return the single element from. predicate − ...
Read More