C
C#8mo ago
Muhammad

❔ ✅ Static

What does static do in classes? I need demos
11 Replies
x0rld
x0rld8mo ago
it doesn't depend of your object instance it depends on the class itself
Muhammad
Muhammad8mo ago
can i get an example? i was looking at a video of it and i didn't understand it fully i don't see the use of it tho but i do
x0rld
x0rld8mo ago
class Foo{
public static StaticBar(){Console.WriteLine("this is not an instance")}
public Bar(){Console.WriteLine("this is an instance")}
}
class Foo{
public static StaticBar(){Console.WriteLine("this is not an instance")}
public Bar(){Console.WriteLine("this is an instance")}
}
Muhammad
Muhammad8mo ago
n i heard a static thingy can only be called via the class itself like Foo.StaticBar();
class Foo{
public static StaticBar(){Console.WriteLine("this is not an instance")}
public Bar(){Console.WriteLine("this is an instance")} // can there be the term static here?
}
class Foo{
public static StaticBar(){Console.WriteLine("this is not an instance")}
public Bar(){Console.WriteLine("this is an instance")} // can there be the term static here?
}
can there be the term static here?
x0rld
x0rld8mo ago
that can be static cause there is no field usage now that can't be
class Foo{
private string things = "test";
public static StaticBar(){Console.WriteLine("this is not an instance")}
public Bar(){Console.WriteLine($"this is an instance {things}")}
}
class Foo{
private string things = "test";
public static StaticBar(){Console.WriteLine("this is not an instance")}
public Bar(){Console.WriteLine($"this is an instance {things}")}
}
Muhammad
Muhammad8mo ago
oh ye what's the difference between private and just not mentioning private at all isn't it the same? it's not public unless written
Sweerpotato
Sweerpotato8mo ago
If you don't specify public or private, internal is the default It means it's only visible to the assembly you're building
Muhammad
Muhammad8mo ago
ah okay thank you xtreit — Today at 23:10 it doesn't depend of your object instance it depends on the class itself !close
Accord
Accord8mo ago
Closed!
Sweerpotato
Sweerpotato8mo ago
No description
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.