C
C#15mo ago
احمد

❔ ✅ Static

What does static do in classes? I need demos
11 Replies
x0rld
x0rld15mo ago
it doesn't depend of your object instance it depends on the class itself
احمد
احمدOP15mo 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
x0rld15mo 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")}
}
احمد
احمدOP15mo 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
x0rld15mo 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}")}
}
احمد
احمدOP15mo 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
Sweerpotato15mo 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
احمد
احمدOP15mo 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
Accord15mo ago
Closed!
Sweerpotato
Sweerpotato15mo ago
No description
Accord
Accord15mo 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.

Did you find this page helpful?