karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 3 of 143

Multiple Where clause in C# Linq

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 5K+ Views

In C# LINQ, you can apply multiple where clauses to filter collections based on different conditions. Each additional where clause further narrows down the results, creating a logical AND relationship between the conditions. Syntax There are two main approaches to using multiple where clauses − Query Syntax with Multiple Where Clauses: var result = from item in collection where condition1 where condition2 ...

Read More

C# program to generate secure random numbers

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 2K+ Views

For secure random numbers, use the RNGCryptoServiceProvider class or the newer RandomNumberGenerator class. These implement cryptographic random number generators that are suitable for security-sensitive applications like generating passwords, tokens, or encryption keys. Secure random numbers differ from regular Random class numbers because they use entropy from the operating system and are cryptographically secure, making them unpredictable even if an attacker knows some previously generated values. Syntax Following is the syntax for generating secure random bytes − using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider()) { byte[] randomBytes = new byte[4]; crypto.GetBytes(randomBytes); ...

Read More

How to calculate the Size of Folder using C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 4K+ Views

To calculate the size of a folder in C#, you need to traverse through all files in the folder and its subdirectories, then sum up their sizes. The DirectoryInfo class provides methods to enumerate files and directories, making this task straightforward. Syntax Following is the syntax for getting folder information and enumerating files − DirectoryInfo info = new DirectoryInfo(@"C:\FolderPath"); long size = info.EnumerateFiles("*", SearchOption.AllDirectories).Sum(file => file.Length); Using DirectoryInfo for Simple Folder Size The most basic approach uses DirectoryInfo.EnumerateFiles() with SearchOption.AllDirectories to include all subdirectories − using System; using System.IO; using System.Linq; ...

Read More

C# Linq Where Method

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 3K+ Views

The Where method in LINQ is used to filter elements from a collection based on a specified condition (predicate). It returns a new IEnumerable containing only the elements that satisfy the given criteria. Syntax The Where method has two overloads − // Filter based on element value only public static IEnumerable Where(this IEnumerable source, Func predicate) // Filter based on element value and index public static IEnumerable Where(this IEnumerable source, Func predicate) Parameters source − The input sequence to filter predicate − A function that tests each element for a condition ...

Read More

C# Nullable Datetime

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 17K+ Views

The nullable DateTime in C# allows you to assign null values to DateTime variables, which is useful when a date might not be available or applicable. This is particularly valuable in database operations where date fields can be NULL, or when dealing with optional date parameters. Syntax A nullable DateTime is declared using the question mark (?) syntax − DateTime? variableName = null; Alternatively, you can use the full Nullable syntax − Nullable variableName = null; Key Properties and Methods Nullable DateTime provides several useful properties and methods − ...

Read More

C# Program to read all the lines of a file at once

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 237 Views

The File.ReadAllText() method in C# reads all the text from a file and returns it as a single string. This method is part of the System.IO namespace and provides a simple way to read entire file contents at once. When you need to read all lines from a text file in one operation, ReadAllText() is more efficient than reading line by line, especially for smaller files. Syntax Following is the syntax for the File.ReadAllText() method − public static string ReadAllText(string path); Parameters path − The file path to read from. Can ...

Read More

Character constants vs String literals in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 527 Views

In C#, both character constants and string literals are used to represent text data, but they serve different purposes and have distinct syntax rules. Character constants represent single characters, while string literals represent sequences of characters (text). Character Constants Character constants are enclosed in single quotes and represent a single character. They are stored in variables of type char. Syntax char variableName = 'character'; Character constants can be − Plain characters − 'x', 'A', '5' Escape sequences − '', '\t', '' Unicode characters − '\u0041' (represents 'A') Example ...

Read More

What is method overloading in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 2K+ Views

Method overloading in C# allows you to define multiple methods with the same name but different parameters. This enables you to create methods that perform similar operations but accept different types or numbers of arguments. Method overloading can be achieved by changing the number of parameters, the data types of parameters, or the order of parameters. The compiler determines which method to call based on the arguments passed at runtime. Syntax Following is the syntax for method overloading − public returnType MethodName(type1 param1) { } public returnType MethodName(type1 param1, type2 param2) { } public returnType ...

Read More

Long Time ("T") Format Specifier in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 502 Views

The Long Time ("T") format specifier in C# is a standard date and time format specifier that displays the time portion of a DateTime value in a long format. This format is culture-sensitive and displays the full time representation including hours, minutes, seconds, and AM/PM designator where applicable. The "T" format specifier is defined by the DateTimeFormatInfo.LongTimePattern property and typically follows the pattern HH:mm:ss for 24-hour format or includes AM/PM for 12-hour format, depending on the culture. Syntax Following is the syntax for using the Long Time format specifier − dateTime.ToString("T") dateTime.ToString("T", CultureInfo.CreateSpecificCulture("culture-name")) ...

Read More

An array of streams in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 839 Views

An array of streams in C# refers to using arrays or collections along with stream objects like StreamWriter and StreamReader to perform file I/O operations. This approach is commonly used when you need to write multiple data items from an array to a file or read file content into an array structure. Syntax Following is the syntax for writing array data to a file using StreamWriter − using (StreamWriter writer = new StreamWriter("filename.txt")) { foreach (dataType item in arrayName) { writer.WriteLine(item); ...

Read More
Showing 21–30 of 1,421 articles
« Prev 1 2 3 4 5 143 Next »
Advertisements