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 806 of 2547
Short Date ("d") Format Specifier
The "d" format specifier in C# represents the short date pattern for formatting DateTime values. This standard format specifier produces a compact date representation without time information, making it ideal for displaying dates in a concise format. The format string is defined by the culture's DateTimeFormatInfo.ShortDatePattern property, which varies based on the current culture settings. Syntax Following is the syntax for using the "d" format specifier − DateTime.ToString("d") DateTime.ToString("d", CultureInfo) The default custom format string for invariant culture is − MM/dd/yyyy Using "d" Format Specifier with Different Cultures ...
Read MoreWhat are the differences between public, protected and private access specifiers in C#?
Access specifiers in C# control the visibility and accessibility of class members. The three primary access specifiers − public, protected, and private − determine where class members can be accessed from, providing different levels of encapsulation and security. Syntax Following is the syntax for declaring members with different access specifiers − public class ClassName { public int publicField; // accessible everywhere protected int protectedField; // accessible in derived classes private int privateField; // accessible ...
Read MoreHow to multiply a given number by 2 using Bitwise Operators in C#?
A number can be multiplied by 2 using bitwise operators. This is done by using the left shift operator (
Read MoreTuple Class in C#
The Tuple class in C# represents a data structure that can hold a sequence of elements. The Tuple class specifically represents a 7-tuple, also called a septet. Tuples provide a convenient way to group multiple values together without creating a custom class. Tuples are commonly used for − Easier access to a data set. Easier manipulation of a data set. To represent a single set of data. To return multiple values from a method To pass multiple values to a method Syntax Following is the syntax for creating a 7-tuple − Tuple ...
Read MoreDecimal.Subtract() Method in C#
The Decimal.Subtract() method in C# is used to subtract two specified decimal values and returns the result. This static method provides a way to perform decimal subtraction with high precision, making it ideal for financial and monetary calculations. Syntax Following is the syntax − public static decimal Subtract(decimal val1, decimal val2); Parameters val1 − The minuend (the number from which another number is to be subtracted). val2 − The subtrahend (the number that is to be subtracted). Return Value Returns a decimal value that represents ...
Read MoreHow to declare and instantiate Delegates in C#?
C# delegates are similar to pointers to functions, in C or C++. A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime, making delegates powerful tools for implementing callback methods and event handling. Syntax Following is the syntax for declaring delegates − delegate Following is the syntax for instantiating delegates − delegateInstance = new (MethodName); Delegate Declaration and Instantiation 1. Declare Delegate delegate int ...
Read MoreHow to find the file using C#?
Use the Directory.GetFiles and Directory.GetDirectories methods in C# to search for files in a directory structure. These methods provide powerful options to recursively search through subdirectories and apply search patterns. Syntax Following is the syntax for finding files using Directory.GetFiles − string[] files = Directory.GetFiles(path, searchPattern, SearchOption.AllDirectories); Following is the syntax for finding directories using Directory.GetDirectories − string[] directories = Directory.GetDirectories(path, searchPattern, SearchOption.AllDirectories); Parameters path − The directory path to search in searchPattern − The search string to match file/folder names (supports wildcards like * and ?) SearchOption ...
Read MoreInsert more than one element at once in a C# List
The InsertRange() method in C# allows you to insert multiple elements into a List at a specified position. This method is useful when you need to add a collection of elements at once rather than adding them one by one. Syntax Following is the syntax for the InsertRange() method − public void InsertRange(int index, IEnumerable collection) Parameters index − The zero-based index at which the new elements should be inserted. collection − The collection whose elements should be inserted into the List. The collection itself cannot be null, but ...
Read MoreC# Enum ToString() Method
The ToString() method in C# enums converts the enum value to its equivalent string representation. This method provides different formatting options to display enum values as either their names or underlying numeric values. Syntax Following are the common syntax forms for enum ToString() method − enumValue.ToString() // Returns name enumValue.ToString("G") // Returns name (General format) enumValue.ToString("d") // Returns decimal value enumValue.ToString("D") // Returns decimal value Parameters ...
Read MoreWhat are accessors of properties in C#?
Properties are an extension of fields and are accessed using the same syntax. They use accessors through which the values of the private fields can be read, written or manipulated. The accessor of a property contains the executable statements that help in getting (reading or computing) or setting (writing) the property. Properties provide a controlled way to access class fields while maintaining encapsulation. Syntax Following is the syntax for property accessors in C# − public datatype PropertyName { get { return fieldName; } ...
Read More