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 78 of 2547
Char.ToLowerInvariant(Char) Method in C#
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 MoreDateTimeOffset.AddSeconds() Method in C#
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 MoreHow to use C# FileStream class?
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 MoreHow to add items to a list in C#?
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 MoreC# program to convert an array to an ordinary list with the same items
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 MoreC# OfType() Method
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 MoreDictionary.Add() Method in C#
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 MoreHow to calculate the Size of Folder using C#?
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 MoreString Template Class in C#
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 MoreC# Linq Where Method
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