Programming Articles

Page 78 of 2547

Char.ToLowerInvariant(Char) Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 265 Views

The Char.ToLowerInvariant() method in C# is used to convert a Unicode character to its lowercase equivalent using the casing rules of the invariant culture. This method ensures consistent case conversion regardless of the current system culture, making it ideal for culture-independent operations. Syntax Following is the syntax − public static char ToLowerInvariant(char ch); Parameters ch − The Unicode character to convert to lowercase. Return Value Returns the lowercase equivalent of the specified character, or the same character if it has no lowercase equivalent or is already lowercase. ...

Read More

DateTimeOffset.AddSeconds() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 384 Views

The DateTimeOffset.AddSeconds() method in C# returns a new DateTimeOffset object that adds a specified number of whole and fractional seconds to the value of the current instance. This method is useful for time calculations where you need to preserve timezone offset information. Syntax Following is the syntax − public DateTimeOffset AddSeconds(double val); Parameters val − A double representing the number of seconds to add. It can be positive (to add seconds) or negative (to subtract seconds). Fractional values are allowed. Return Value Returns a new DateTimeOffset object whose value is the ...

Read More

How to use C# FileStream class?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 407 Views

The FileStream class in C# provides a stream for file operations such as reading from and writing to files. It is part of the System.IO namespace and allows byte-level access to files on the file system. FileStream is useful when you need direct control over file operations, especially for binary data or when working with large files efficiently. Syntax Following is the basic syntax for creating a FileStream object − FileStream fileStream = new FileStream(path, FileMode, FileAccess); The FileMode parameter specifies how the file should be opened − FileMode.OpenOrCreate // ...

Read More

How to add items to a list in C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 996 Views

In C#, you can add items to a List using several methods. The most common approach is using the Add() method to add single items, but there are also methods to add multiple items at once. Syntax Following is the syntax for creating a list and adding items − var listName = new List(); listName.Add(item); To add multiple items at once − listName.AddRange(collection); Using Add() Method The Add() method adds a single item to the end of the list − using System; using System.Collections.Generic; public class ...

Read More

C# program to convert an array to an ordinary list with the same items

Samual Sam
Samual Sam
Updated on 17-Mar-2026 145 Views

Converting an array to a list is a common operation in C#. There are several ways to achieve this conversion, from manual iteration to using built-in methods that make the process more efficient and concise. Using Manual Loop The most straightforward approach is to create an empty list and add each array element using a loop − using System; using System.Collections.Generic; public class Program { public static void Main() { int[] arr = { 23, 66, 96, 110 }; var ...

Read More

C# OfType() Method

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 716 Views

The OfType() method in C# is a LINQ extension method that filters a collection based on the type of its elements. It returns only the elements that match the specified type, making it useful for working with heterogeneous collections containing different data types. Syntax Following is the syntax for the OfType() method − public static IEnumerable OfType(this IEnumerable source) The method can be used with both method syntax and query syntax − // Method syntax var result = collection.OfType(); // Query syntax var result = from item in collection.OfType() select item; ...

Read More

Dictionary.Add() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 350 Views

The Dictionary.Add() method in C# is used to add a specified key-value pair to the dictionary. This method adds elements to the dictionary and throws an exception if you try to add a duplicate key. Syntax Following is the syntax − public void Add(TKey key, TValue value) Parameters key − The key of the element to add. Cannot be null. value − The value of the element to add. Can be null for reference types. Return Value This method does not return any value. It ...

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

String Template Class in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 523 Views

The StringTemplate class is part of the NString library that provides enhanced string formatting capabilities in C#. It offers a more readable alternative to String.Format by using named placeholders instead of numbered ones, making code less error-prone and easier to maintain. The StringTemplate class comes with the NString library, which includes several useful extension methods for string manipulation such as IsNullOrEmpty(), IsNullOrWhiteSpace(), Join(), Truncate(), Left(), Right(), and Capitalize(). Syntax The basic syntax for StringTemplate.Format uses named placeholders − string result = StringTemplate.Format("{PropertyName}", new { PropertyName = value }); For formatting with specific format ...

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
Showing 771–780 of 25,467 articles
« Prev 1 76 77 78 79 80 2547 Next »
Advertisements