Samual Sam

Samual Sam

1,507 Articles Published

Articles by Samual Sam

Page 15 of 151

Short Date ("d") Format Specifier

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

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 More

What are the differences between public, protected and private access specifiers in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 3K+ Views

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 More

How to declare and instantiate Delegates in C#?

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

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 More

Get the range of elements in a C# list

Samual Sam
Samual Sam
Updated on 17-Mar-2026 3K+ Views

The GetRange() method in C# is used to extract a subset of elements from a List. This method returns a new list containing the specified range of elements from the original list, without modifying the original list. Syntax Following is the syntax for the GetRange() method − public List GetRange(int index, int count) Parameters index − The zero-based starting index of the range to extract. count − The number of elements to extract from the starting index. Return Value Returns a new List containing the specified range of elements. ...

Read More

Null List in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

A null list in C# refers to a List reference that points to nothing instead of an actual List object. This is different from an empty list, which is an initialized List with zero elements. Understanding null lists is crucial for avoiding NullReferenceException errors in your applications. Syntax To declare a null list − List listName = null; To check if a list is null − if (listName == null) { // handle null case } Creating and Checking Null Lists When you declare a List ...

Read More

How to declare variables in C#?

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

Each variable in C# has a specific type, which determines the size and layout of the variable's memory, the range of values that can be stored within that memory, and the set of operations that can be applied to the variable. Variables must be declared before they can be used. Declaration tells the compiler what type of data the variable will hold and reserves memory accordingly. Syntax Following is the basic syntax for declaring variables in C# − ; You can also declare multiple variables of the same type in a single ...

Read More

Are arrays zero indexed in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 1K+ Views

Yes, arrays are zero-indexed in C#. This means the first element of an array is stored at index 0, the second element at index 1, and so on. The relationship between array length and indexing follows a consistent pattern. Array Length vs Index Range If the array is empty, it has zero elements and length 0. If the array has one element at index 0, then it has length 1. If the array has two elements at indexes 0 and 1, then it has length 2. If the array has ...

Read More

How to reverse a String using C#?

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

In C# there are multiple ways to reverse a string. The most common approach is using the Array.Reverse() method, but you can also use other techniques like loops or LINQ methods for different scenarios. Using Array.Reverse() Method The Array.Reverse() method is the most efficient way to reverse a string. First, convert the string to a character array, then apply the reverse method − using System; class Program { static void Main(string[] args) { string str = "Amit"; ...

Read More

C# Currency ("C") Format Specifier

Samual Sam
Samual Sam
Updated on 17-Mar-2026 33K+ Views

The C format specifier (currency) is used to format numeric values as currency amounts. It automatically applies the appropriate currency symbol, decimal places, and thousands separators based on the current culture settings. Syntax Following is the syntax for using the currency format specifier − value.ToString("C") // Default currency format value.ToString("C3") // Currency with 3 decimal places value.ToString("C", culture) // Currency with specific culture The precision specifier (optional number after C) determines how many decimal ...

Read More

Three Different ways to calculate factorial in C#

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

The factorial of a number is the product of all positive integers less than or equal to that number. For example, factorial of 5 (written as 5!) is 5 × 4 × 3 × 2 × 1 = 120. In C#, you can calculate factorial using three different approaches − Syntax The mathematical definition of factorial is − n! = n × (n-1) × (n-2) × ... × 2 × 1 0! = 1 (by definition) 1! = 1 Factorial Calculation Methods For Loop ...

Read More
Showing 141–150 of 1,507 articles
« Prev 1 13 14 15 16 17 151 Next »
Advertisements