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
Server Side Programming Articles
Page 822 of 2109
Month ("M", "m") Format Specifier in C#
The Month ("M", "m") format specifier in C# represents a custom date and time format string that displays the month and day portions of a date. This format specifier is defined by the current DateTimeFormatInfo.MonthDayPattern property and typically follows the pattern MMMM dd. Syntax Following is the syntax for using the Month format specifier − dateTime.ToString("M") dateTime.ToString("m") The custom format string pattern is − MMMM dd Using Month Format Specifier Basic Example using System; using System.Globalization; class Demo { static void Main() ...
Read MoreShort Time ("t") Format Specifier in C#
The Short Time format specifier ("t") in C# is a standard date and time format specifier that displays only the time portion of a DateTime in a short format. It excludes the date and seconds, showing only hours and minutes along with the AM/PM designator for 12-hour formats. The "t" format specifier is defined by the DateTimeFormatInfo.ShortTimePattern property of the current culture. Different cultures may display the time differently based on their regional settings. Syntax Following is the syntax for using the short time format specifier − DateTime.ToString("t") DateTime.ToString("t", CultureInfo) The underlying custom ...
Read MoreCollection Initialization in C#
Collection initialization in C# allows you to initialize collections with values at the time of creation using a concise syntax. This feature, introduced in C# 3.0, makes code more readable and eliminates the need for multiple Add() method calls. Collection initializers work with any collection type that implements IEnumerable and has an Add method, including List, Dictionary, arrays, and custom collections. Syntax Following is the syntax for collection initialization − CollectionType collectionName = new CollectionType { item1, item2, item3 }; For objects with properties, you can combine object and collection initialization − ...
Read MoreAction Delegate in C#
The Action delegate in C# is a built-in generic delegate type that represents a method with no return value (void). It can accept zero or more input parameters and is particularly useful for passing methods as parameters or storing method references. Syntax Following is the basic syntax for declaring an Action delegate − Action actionDelegate = MethodName; For Action delegates with parameters − Action actionDelegate = MethodName; Action actionDelegate = MethodName; Action actionDelegate = MethodName; Where T, T1, T2, etc. are the parameter types. Using Action Delegate with Single ...
Read MoreMultiple Where clause in C# Linq
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 MoreC# Enum IsDefined Method
The Enum.IsDefined method in C# determines whether a specified value exists within a given enumeration. It returns true if the value is found, either as an integral value or its corresponding string name, and false otherwise. Syntax Following is the syntax for the Enum.IsDefined method − public static bool IsDefined(Type enumType, object value) Parameters enumType − The type of the enumeration to check against. value − The value to look for in the enumeration (can be an integer or string). Return Value Returns true if the specified value exists ...
Read MoreC# int.Parse Method
The int.Parse method in C# converts a string representation of a number to an integer. If the string cannot be converted to a valid integer, the method throws a FormatException. Syntax Following is the basic syntax for int.Parse − int result = int.Parse(stringValue); The method also has overloaded versions that accept additional parameters − int result = int.Parse(stringValue, NumberStyles.Integer); int result = int.Parse(stringValue, CultureInfo.InvariantCulture); Parameters s − A string containing a number to convert. style (optional) − A bitwise combination of enumeration values that indicates ...
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 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 MoreC# Program to make a copy of an existing file
The File.Copy method in C# is used to copy an existing file from one location to another. This method is part of the System.IO namespace and provides a simple way to duplicate files programmatically. Syntax Following is the syntax for the File.Copy method − File.Copy(string sourceFileName, string destFileName); File.Copy(string sourceFileName, string destFileName, bool overwrite); Parameters sourceFileName − The path of the file to copy. destFileName − The path of the destination file. overwrite − Optional boolean parameter. If true, overwrites the destination file if it already exists. ...
Read More