What does it mean when you add the static keyword to a method?
public static void doSomething(){
//Well, do something!
}
Can you add the
From another point of view: Consider that you want to make some changes on a single String. for example you want to make the letters Uppercase and so on. you make another class named "Tools" for these actions. there is no meaning of making instance of "Tools" class because there is not any kind of entity available inside that class (compare to "Person" or "Teacher" class). So we use static keyword in order to use "Tools" class without making any instance of that, and when you press dot after class name ("Tools") you can have access to the methods you want.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Tools.ToUpperCase("Behnoud Sherafati"));
Console.ReadKey();
}
}
public static class Tools
{
public static string ToUpperCase(string str)
{
return str.ToUpper();
}
}
}