Sunday, 28 April 2024

What is the use of static class?

 What is the use of static class?

Static classes are used as containers for static members. Static methods and static properties are the most-used members of a static class. All static members are called directly using the class name. Static methods do a specific job and are called directly using a type name, rather than the instance of a type.
When to use static classes in C#?
Static classes and members are usually used for data or functions that do not change in response to object state, or for utility functions that do not rely on object state at all. One common use of static classes is to hold application-level data, such as configuration

static void Main(string[] args)
{
    string sourceString, reversestring;
    Reversestring(out sourceString, out reversestring);
    Console.WriteLine("sourece string is {0} \n reverse string is {1}", sourceString, reversestring);
    Console.ReadLine();

}
private static void Reversestring(out string sourceString, out string reversestring)
{
    reversestring = "";
    Console.WriteLine("Please Enter string you would like to revese");
    sourceString = Console.ReadLine();
    for (int i = sourceString.Length - 1; i >= 0; i--)
    {
        reversestring += sourceString[i];
    }
}

No comments:

Post a Comment

Car pooling app

 I'll create a car pooling app with real-time vehicle tracking, pickup/drop time estimates, and a list of onboard users. Since we don...