Showing posts with label C# Example. Show all posts
Showing posts with label C# Example. Show all posts

C# Program to Remove Spaces in a String.

Problem: Given a string str, you need to remove all the whitespace from the given string and return a new string without spaces. Write a C# code to solve this problem of removing all spaces from the given string.

Example:

Input: Hello AlgoLesson
Output: HelloAlgoLesson

Input: Good Morning
Output: GoodMorning

We can solve this problem with multiple approaches and here we are going to discuss three different approaches to solve this.

Approach 1: Using string.Replace Method.

In this approach, we use the built-in string.Replace method to replace spaces with an empty string. We will call the Replace method on the input string and provide two arguments: the first argument is the character or substring to be replaced (in this case, a space), and the second argument is the replacement string (an empty string ""). 

Example C# Code:
// C# code implementation to remove whitespace from string
using System;

public class HelloWorld
{
    public static string RemoveSpacesUsingReplace(string input)
    {
        return input.Replace(" ", "");
    }
    public static void Main(string[] args)
    {
        string str = "Welcome to AlgoLesson";
        string result = RemoveSpacesUsingReplace(str);
        
        Console.WriteLine ("With Whitespace: " + str);
        Console.WriteLine ("Without Whitespace: " + result);
    }
}
Output:
With Whitespace: Welcome to AlgoLesson
Without Whitespace: WelcometoAlgoLesson

Approach 2: Using string.Join Method.

This approach splits the input string into an array of substrings using spaces as separators and then joins the substrings together without spaces. We use the Split method to split the input string into an array of substrings. The new[] { ' ' } argument specifies that we want to split the string at spaces. StringSplitOptions.RemoveEmptyEntries removes any empty substrings resulting from consecutive spaces. We then use string.Join to concatenate the array of substrings into a single string without spaces.

Example C# Code:
// C# code implementation to remove whitespace from string using Join method
using System;

public class AlgoLesson
{
    public static string RemoveSpacesUsingSplitAndJoin(string input)
    {
        string[] words = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        return string.Join("", words);
    }
    public static void Main(string[] args)
    {
        string str = "Welcome to AlgoLesson";
        string result = RemoveSpacesUsingSplitAndJoin(str);
        
        Console.WriteLine ("With Whitespace: " + str);
        Console.WriteLine ("Without Whitespace: " + result);
    }
}
Output:
With Whitespace: Welcome to AlgoLesson
Without Whitespace: WelcometoAlgoLesson

Approach 3: Using string Builder.

This approach uses a StringBuilder to efficiently remove spaces by appending non-space characters. We initialize a StringBuilder (sb) to build the resulting string. We iterate through each character in the input string. If a character is not a space, we append it to the StringBuilder. After processing all characters, we convert the StringBuilder to a string using the ToString method and return the cleaned string.

Example C# Code:

// C# code implementation to remove whitespace from string using string builder
using System;

public class HelloWorld
{
    public static string RemoveSpacesUsingStringBuilder(string input)
    {
        StringBuilder sb = new StringBuilder();
    
        foreach (char c in input)
        {
            if (c != ' ')
            {
                sb.Append(c);
            }
        }
    
        return sb.ToString();
    }
    public static void Main(string[] args)
    {
        string str = "Welcome to AlgoLesson";
        string result = RemoveSpacesUsingSplitAndJoin(str);
        
        Console.WriteLine ("With Whitespace: " + str);
        Console.WriteLine ("Without Whitespace: " + result);
    }
}
Output:
With Whitespace: Welcome to AlgoLesson
Without Whitespace: WelcometoAlgoLesson

These are four different approaches to removing spaces from a string in C#. You can choose the one that best suits your specific requirements and coding style.

C# Program Remove Special Characters from String.

In C#, multiple ways exist to remove special characters from a given string. This is a significant problem that we often face when we try to compare two different strings. In this article, we are going to discuss three different ways to remove special characters from a given string.


Approach 1: Using Regular Expressions.

You can utilize regular expressions (Regex) to remove special characters from a string in C#. This method is flexible and allows you to specify which characters to keep or remove.

Example Code: 

// C# program to remove special character using regular expression

using System;
using System.Text.RegularExpressions;

public class HelloWorld
{
    static string RemoveSpecialCharactersRegex(string input)
    {
        // Regular expression pattern to match special characters
        string pattern = @"[^a-zA-Z0-9\s]";
        
        // Regex.Replace to remove special characters from the input string
        return Regex.Replace(input, pattern, "");
    }
    
    public static void Main(string[] args)
    {
        string inputString = "Hello, @World! 123";
        
        // Remove special characters from the input string using Regex
        string result = RemoveSpecialCharactersRegex(inputString);
        
        Console.WriteLine("Original String: " + inputString);
        Console.WriteLine("String with Special Characters Removed: " + result);
    }
}
Output:
Original String: Hello, @World! 123
String with Special Characters Removed: Hello World 123

Approach 2: Using LINQ and Char.IsLetterOrDigit.

You can use LINQ to filter out characters that are letters or digits, effectively removing special characters. This approach will also remove spaces between two words if exist.

Example Code: 

// C# code to remove speical characters from string using LINQ

using System;
using System.Linq;

public class Program
{
    static string RemoveSpecialCharactersLinq(string input)
    {
        // Use LINQ to filter out non-alphanumeric characters and spaces
        string cleanedString = new string(input.Where(char.IsLetterOrDigit).ToArray());
        return cleanedString;
    }

    static void Main(string[] args)
    {
        string inputString = "Hello, @World! 123";
        
        // Remove special characters from the input string using LINQ
        string result = RemoveSpecialCharactersLinq(inputString);
        
        Console.WriteLine("Original String: " + inputString);
        Console.WriteLine("String with Special Characters Removed: " + result);
    }
}
Output:
Original String: Hello, @World! 123
String with Special Characters Removed: HelloWorld123


Approach 3: Using a String Builder.

Using a StringBuilder is a memory-efficient approach for removing special characters from a string. The key advantage of this approach is that it minimizes memory overhead compared to creating multiple string objects. 

Example Code:
// C# code to remove special character using stringbuider function
using System;
using System.Text;

public class Program
{
    static string RemoveSpecialCharactersStringBuilder(string input)
    {
        StringBuilder sb = new StringBuilder();
        
        foreach (char c in input)
        {
            if (char.IsLetterOrDigit(c) || char.IsWhiteSpace(c))
            {
                sb.Append(c);
            }
        }
        
        return sb.ToString();
    }

    static void Main(string[] args)
    {
        string inputString = "Hello, @World! 123";
        
        // Remove special characters from the input string using a StringBuilder
        string result = RemoveSpecialCharactersStringBuilder(inputString);
        
        Console.WriteLine("Original String: " + inputString);
        Console.WriteLine("String with Special Characters Removed: " + result);
    }
}
Output:
Original String: Hello, @World! 123
String with Special Characters Removed: Hello World 123

All three approaches will remove special characters and return a string containing only alphanumeric characters and spaces. You can choose the method that best fits your requirements and coding style.

Variables in C#.

Variables are fundamental building blocks in the world of programming. They serve as containers for storing data that your program can read, modify, and utilize during its execution. In this article, we are going to learn about the types of variables available in C# and how to declare and define them in our program.


Types of Variables in C#.

In C#, variables come in two primary categories: value types and reference types. The choice between these types depends on the kind of data you want to store and how you intend to use it. Let's learn each type one by one in detail.


1. Value Type Variables.

Value types directly store the data value itself. They are stored in memory, and when you copy or pass a value type variable to a method or another variable, you're working with a copy of the actual data. 

Here is the list of a few commonly used Value Type variables in C#:

  • int: Represents integer numbers.
  • float: Represents single-precision floating-point numbers.
  • double: Represents double-precision floating-point numbers.
  • bool: Represents Boolean values (true or false).
  • char: Represents a single character.
  • struct: Represents user-defined value types.

Example:

// Value type variables
int age = 25;
float temperature = 98.6f;
bool isStudent = true;

2. Reference Type Variables.

Reference types store a reference (memory address) to the actual data stored elsewhere in memory. When you copy or pass a reference type variable, you're working with a reference to the same data.

Here is the list of a few commonly used Reference Type variables in C#:

    • string: Represents a sequence of characters.
    • class: Represents user-defined reference types.
    • interface: Defines a contract for classes to implement.
    • delegate: Represents a method that can be passed as an argument.
    • object: The base type for all other types in C#.
    Example:
    // Reference Type Variable
    string name = "John";
    List<int> numbers = new List<int> { 1, 2, 3 };
    

    Declaring and Initializing Variables.

    In C#, you declare a variable by specifying its data type followed by a name for the variable. You can also assign an initial value during declaration or assign a value later in your code. 

    Example:
    // Declaration with initialization
    int age = 25;
    
    // Declaration without initialization
    float temperature;
    
    // Assignment after declaration
    temperature = 98.6f;
    

    You can also declare multiple variables of the same type in a single line:
    int x = 5, y = 10, z = 15;
    

    Rules for Variable Names.

    Variable names in C# must adhere to specific rules to ensure the readability and maintainability of your code. Here are some essential rules for naming variables:
    • Variable names are case-sensitive, so myVariable and MyVariable are different.
    • Names can consist of letters, digits, and the underscore character _.
    • Names must begin with a letter or an underscore.
    • Variable names cannot be a C# keyword or reserved word (e.g., int, class, if).
    Here are some examples of invalid variable names:
    int 123number;         // Starts with a digit.
    string my-variable;    // Contains an invalid character (-).
    double if;             // Uses a C# keyword as a name.
    

    Best Practice for Variable Naming.

    To write clean, maintainable code, consider following these best practices for variable naming:
    • Use descriptive names that convey the variable's purpose. For example, use totalAmount instead of amt.
    • Follow a consistent naming convention. Common conventions include PascalCase for class names (MyClass), camelCase for method and variable names (myVariable), and UPPERCASE for constants (MAX_VALUE).
    • Avoid using single-letter variable names, except for loop counters (i, j, k) or generic type parameters (T).
    • Use meaningful prefixes or suffixes when necessary. For instance, prefix boolean variables with "is" or "has" (isLoggedIn, hasPermission).
    • Keep variable names concise but not overly abbreviated. Aim for a balance between clarity and brevity.
    I hope you got a basic understanding of variables in C# and how to define or declare them. You should always create a meaningful variable that helps others to understand the use and purpose of that variable in the program.

    C# Keywords and Identifiers.

    When you dive into the world of C# programming, you encounter various building blocks that form the foundation of your code. Two fundamental concepts you'll frequently encounter are keywords and identifiers. Understanding what these are, how they work, and their significance is crucial for writing clean, efficient, and readable code.

    Keywords in C#.

    Keywords are predefined words in C# that have special meanings and purposes. They are reserved for specific roles within the language and cannot be used as identifiers, such as variable or method names. Keywords provide the structure and logic for your code.

    C# has a rich set of keywords that are integral to its syntax and functionality. Let's explore some of these keywords with examples:

    Example:
    class Person {
        public string Name { get; set; }
        
        public void Greet() {
            Console.WriteLine("Hello, " + Name);
        }
    }
    

    Here, class, public, string, get, set, void, return, and Console are keywords used to define a class and its properties and methods. 

    Identifiers in C#.

    Identifiers are user-defined names for program elements such as variables, classes, methods, and parameters. They help make your code more readable and understandable. 

    Identifiers must adhere to these rules:
    • Begin with a letter (uppercase or lowercase) or an underscore.
    • Subsequent characters can be letters, digits, or underscores.
    • C# is case-sensitive, so MyVariable and myvariable are distinct identifiers.
    • Avoid using C# keywords as identifiers.
    Valid identifiers: myVariable, _privateField, CalculateArea, StudentRecord.
    Invalid identifiers: 3rdPlace (starts with a digit), class (a C# keyword).

    Example:
    int numberOfApples = 10;
    string studentName = "John";
    

    In this example, numberOfApples and studentName are identifiers used for variables.

    Use of Keywords and Identifiers.

    Keywords and identifiers work together in C# code to create and manipulate program elements.

    1. Keywords and Identifiers are used together for Declaring Variables.
    int age; // 'int' is a keyword, 'age' is an identifier
    age = 25;
    

    2. Keywords and Identifiers are used together for Defining Classes.
    class Circle {
        public double Radius { get; set; } // 'class', 'public', 'double', and 'Radius' are keywords and identifiers
        public double CalculateArea() {
            return Math.PI * Radius * Radius; // 'Math', 'PI', '*' are keywords and identifiers
        }
    }
    

    3. Keywords and Identifiers are used together for Method Naming.
    public void SayHello(string name) {
        Console.WriteLine("Hello, " + name); // 'SayHello', 'string', 'name', '+' are keywords and identifiers
    }
    

    From the above examples, you got an idea of how and where we can use keywords and identifiers in our C# code. 

    Contextual Keywords in C#.

    Contextual keywords in C# are a special set of identifiers with a specific meaning within a particular context in the C# programming language. Unlike regular keywords, which have predefined meanings and cannot be used as identifiers, contextual keywords only have significance in specific code contexts where they are relevant. In other contexts, they can be used as regular identifiers like variable names or class names.

    Example:
    // Contextual Keywords
    var query = from student in students
                where student.Age > 18
                select student;
    

    Here in the above example, var, from, where, and select are contextual keywords used in LINQ queries.

    Conclusion.

    Keywords and identifiers are the building blocks of your C# code. Keywords define the language's structure and logic, while identifiers give names to program elements. Understanding their roles and using them effectively is essential for writing clean, maintainable code.

    C# Sharp History and Versions.

    C# (pronounced "C-sharp") is a versatile, high-level programming language developed by Microsoft Corporation. Since its inception, C# has become one of the most popular and widely used programming languages, powering a broad range of applications in various domains.

    Founder of C# Programming Anders Hejlsberg

    History of C# Programming.

    C# was created by Microsoft as part of its .NET initiative in the early 2000s. The language was designed by Anders Hejlsberg, a Danish computer programmer with a remarkable track record in developing programming languages. Hejlsberg had previously worked on Turbo Pascal and Delphi, and his expertise greatly contributed to C#'s success.

    The development of C# began in 1999, and it was officially introduced to the public in 2000 as part of Microsoft's .NET Framework 1.0. C# was positioned as the primary language for building Windows applications on the .NET platform.

    C# Relation with .Net.

    C# is closely associated with the .NET ecosystem, a comprehensive framework for building Windows applications and web services. The language was designed to work seamlessly with the .NET Framework, enabling developers to create a wide range of applications, from desktop software to web applications and cloud services.

    Different Versions of C# Available.

    C# has gone through several iterations, with each version introducing new features, improvements, and capabilities. Here is a brief overview of the major C# versions:

    C# 1.0 (2000): The initial release of C# included fundamental features like classes, inheritance, interfaces, and garbage collection. It was tightly integrated with the .NET Framework 1.0.

    C# 2.0 (2005): C# 2.0 brought generics, partial classes, anonymous methods, and nullable value types. These additions improved code reusability and made it easier to work with collections.

    C# 3.0 (2007): C# 3.0 introduced language enhancements such as lambda expressions, extension methods, and the LINQ (Language Integrated Query) framework. These features streamlined data manipulation and querying.

    C# 4.0 (2010): Version 4.0 introduced optional and named parameters, dynamic types, and improved support for COM interop. These additions enhanced code flexibility and interoperation with other languages.


    C# 5.0 (2012): C# 5.0 introduced asynchronous programming using the async and await keywords. This feature simplified the development of asynchronous and responsive applications.


    C# 6.0 (2015): C# 6.0 added features like string interpolation, null-conditional operators (?. and ?[]), and read-only properties and auto-properties. These features aimed to improve code readability and reduce boilerplate code.


    C# 7.0 (2017): C# 7.0 brought enhancements such as pattern matching, local functions, and tuples. These features enhanced code expressiveness and simplification.

    C# 8.0 (2019): C# 8.0 introduced several significant features, including nullable reference types, asynchronous streams, and default interface methods. These additions improved code safety and versatility.

    C# 9.0 (2020): C# 9.0, introduced record types, pattern-matching improvements, and new features for simplifying code. It also introduced source generators, allowing developers to generate code at compile time.

    C# 10.0 (2021): C# 10.0 was released in the year 2021 and contains several features like global using directives, interpolated strings as format strings, file-scoped namespaces, and more.

    How To Validate Email ID in C#?

    Validating email addresses is a common task in C# applications, especially when dealing with user input or processing email-related functionality. It is very important to validate an Email ID before storing it in our database.


    All Email IDs must follow a specific format and must belong to some domain. Here in this article, we are going to cover three different methods that we can use for email validation. 


    Email Format Validation.

    In C# we can validate an Email ID using the below methods:

    • Using Regular Expression.
    • Using Built-in Library Function.
    • Using Custom Validation.

    Let's understand each of these methods in detail with C-sharp Code.


    Method 1: Using Regular Expression.

    Using a regular expression is a robust way to validate email addresses. It allows you to define complex patterns that match valid email formats.


    C# Example Code:

    // C#-sharp code to validate email id using Regular Expression
    using System;
    using System.Text.RegularExpressions;
    
    class EmailValidator
    {
        public static bool IsValidEmail(string email)
        {
            // Define a regular expression pattern for valid email addresses
            string pattern = @"^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$";
    
            // Use Regex.IsMatch to check if the email matches the pattern
            return Regex.IsMatch(email, pattern);
        }
    
        static void Main()
        {
            string email = "example@email.com";
            bool isValid = IsValidEmail(email);
            
            Console.WriteLine($"Is {email} a valid email address? {isValid}");
        }
    }
    
    Output:
    Is example@email.com a valid email address? True
    

    Explanation of Above C# Code:
    • We define a regular expression pattern that describes valid email addresses.
    • The pattern ^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$ checks for common email format rules.
    • Regex.IsMatch(email, pattern) tests if the email string matches the pattern.
    • The IsValidEmail method returns true if the email is valid.

    Method 2: Using Regular Expression.

    C# also provides a built-in library, System.Net.Mail, for email-related tasks, including email address validation.

    C# Example Code:

    // C#-sharp code to validate email id using Built-in Library
    using System;
    using System.Net.Mail;
    
    class EmailValidator
    {
        public static bool IsValidEmail(string email)
        {
            try
            {
                var mailAddress = new MailAddress(email);
                return true;
            }
            catch (FormatException)
            {
                return false;
            }
        }
    
        static void Main()
        {
            string email = "algolesson@email.com";
            bool isValid = IsValidEmail(email);
            
            Console.WriteLine($"Is {email} a valid email address? {isValid}");
        }
    }
    
    Output:
    Is algolesson@email.com a valid email address? True
    

    Explanation of Above C# Code:
    • We create a MailAddress object with the given email string.
    • If the email string is not a valid email address, a FormatException is thrown.
    • We catch the exception and return false for invalid emails.

    Method 3: Using Custom Validation.

    For basic validation without using regular expressions or libraries, you can implement a simple custom validation method.

    C# Example Code:

    // C#-sharp code to validate email id using Custom Validation
    using System;
    
    class EmailValidator
    {
        public static bool IsValidEmail(string email)
        {
            if (string.IsNullOrWhiteSpace(email))
                return false;
    
            if (!email.Contains("@") || !email.Contains("."))
                return false;
    
            // Additional checks can be added based on your requirements
            
            return true;
        }
    
        static void Main()
        {
            string email = "algolesson@email.com";
            bool isValid = IsValidEmail(email);
            
            Console.WriteLine($"Is {email} a valid email address? {isValid}");
        }
    }
    
    Output:
    Is algolesson@email.com a valid email address? True
    

    Explanation of Above C# Code:
    • We perform basic checks like ensuring the email is not null or empty and contains both "@" and ".".
    • You can add additional checks based on your specific requirements.

    So these are a few methods that you can use to validate your email id in C# choose any one of them that is best for you according to your use and requirement.

    C# Program to Formats Data and Time Value.

    Date and time values are crucial in applications for various purposes, such as displaying timestamps, scheduling events, or formatting data for reports. In C#, the DateTime structure is used to work with date and time values. You can format these values into human-readable strings using the ToString method.


    The format string used with the DateTime.ToString method allows you to customize how the date and time are displayed. Here we are going to look at some examples of format strings and the resulting formatted date and time:


    1. "yyyy-MM-dd HH:mm:ss": This format string displays the date and time in the format "Year-Month-Day Hour:Minute:Second."

    C# Code:

    // C-sharp program to print current date and time
    using System;
    
    public class HelloWorld
    {
        public static void Main(string[] args)
        {
            DateTime dateTime = DateTime.Now;
            string formattedDateTime = dateTime.ToString("yyyy-MM-dd HH:mm:ss");
            Console.WriteLine(formattedDateTime);
        }
    }
    
    Output:
    2023-09-02 14:46:04
    

    2. "dd/MM/yyyy": This format string displays the date in the format "Day/Month/Year."

    C# Code:

    // C-sharp program to print current date and time
    using System;
    
    public class HelloWorld
    {
        public static void Main(string[] args)
        {
            DateTime dateTime = DateTime.Now;
            string formattedDateTime = dateTime.ToString("dd/MM/yyyy");
            Console.WriteLine(formattedDateTime);
        }
    }
    
    Output:
    25/09/2023
    

    3. "MMMM dd, yyyy": This format string displays the date as "Month Day, Year."

    C# Code:

    // C-sharp program to print current date and time
    using System;
    
    public class HelloWorld
    {
        public static void Main(string[] args)
        {
            DateTime dateTime = DateTime.Now;
            string formattedDateTime = dateTime.ToString("MMM dd, yyyy");
            Console.WriteLine(formattedDateTime);
        }
    }
    
    Output:
    July 24, 2023
    

    4. "hh:mm tt": This format string displays the time in a 12-hour clock format with "AM" or "PM."

    C# Code:

    // C-sharp program to print current date and time
    using System;
    
    public class HelloWorld
    {
        public static void Main(string[] args)
        {
            DateTime dateTime = DateTime.Now;
            string formattedDateTime = dateTime.ToString("hh:mm tt");
            Console.WriteLine(formattedDateTime);
        }
    }
    
    Output:
    04:40 PM

    I hope you get some idea about how to get date and time values in the C# programming language. There are many different ways to customize and format the Date and Time value.

    Basic Format Specifiers.

    Below is the list of some commonly used Format Specifiers:
    • "d": Short date pattern (e.g., "7/25/2023").
    • "D": Long date pattern (e.g., "Monday, July 25, 2023").
    • "t": Short time pattern (e.g., "3:30 PM").
    • "T": Long time pattern (e.g., "3:30:45 PM").
    • "f": Full date and short time pattern (e.g., "Monday, July 25, 2023 3:30 PM").
    • "F": Full date and long time pattern (e.g., "Monday, July 25, 2023 3:30:45 PM").
    • "g": General date and short time pattern (e.g., "7/25/2023 3:30 PM").
    • "G": General date and long time pattern (e.g., "7/25/2023 3:30:45 PM").
    • "yyyy-MM-dd": Custom date format (e.g., "2023-07-25").
    • "HH:mm:ss": Custom time format (e.g., "15:30:45").

    Custom Format Specifiers.

    In addition to the predefined format specifiers, you can create custom format strings. Here's how to use some common custom specifiers:
    • "yyyy": Four-digit year (e.g., "2023").
    • "MM": Two-digit month (e.g., "07" for July).
    • "dd": Two-digit day (e.g., "25").
    • "HH": Two-digit hour (24-hour clock, e.g., "15").
    • "hh": Two-digit hour (12-hour clock, e.g., "03").
    • "mm": Two-digit minute (e.g., "30").
    • "ss": Two-digit second (e.g., "45").
    • "fff": Milliseconds (e.g., "123").

    C# Code to Customize Data and Time Format.

    // C-sharp program to customize current date and time
    using System;
    
    public class HelloWorld
    {
        public static void Main(string[] args)
        {
            DateTime now = DateTime.Now;
            
            // "7/25/2023"
            string shortDate = now.ToString("d"); 
            // "Monday, July 25, 2023"
            string longDate = now.ToString("D"); 
            // "3:30 PM"
            string shortTime = now.ToString("t");
            // "3:30:45 PM"
            string longTime = now.ToString("T");
            // "Monday, July 25, 2023 3:30"
            string fullDateTime = now.ToString("F");
            // "2023-07-25 15:30:45"
            string customFormat = now.ToString("yyyy-MM-dd HH:mm:ss"); 
            
            Console.WriteLine(shortDate);
            Console.WriteLine(longDate);
            Console.WriteLine(shortTime);
            Console.WriteLine(longTime);
            Console.WriteLine(fullDateTime);
            Console.WriteLine(customFormat);
        }
    }
    
    Output:
    09/02/2023
    Saturday, 02 September 2023
    15:22
    15:22:07
    Saturday, 02 September 2023 15:22:07
    2023-09-02 15:22:07
    

    Formatting date and time values in C# is essential for displaying information to users or storing timestamps in a specific format. By using format specifiers, you can control how date and time values are presented. Understanding the available format options and creating custom formats when necessary will help you work effectively with date and time values in your C# applications.

    DON'T MISS

    Tech News
    © all rights reserved
    made with by AlgoLesson