C
C#14mo ago
Ahmed

❔ ✅ Static

What does static do in classes? I need demos
11 Replies
x0rld 👻 🎃
x0rld 👻 🎃14mo ago
it doesn't depend of your object instance it depends on the class itself
Ahmed
AhmedOP14mo 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 👻 🎃
x0rld 👻 🎃14mo 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")}
}
Ahmed
AhmedOP14mo 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 👻 🎃
x0rld 👻 🎃14mo 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}")}
}
Ahmed
AhmedOP14mo 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
Sweerpotato14mo 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
Ahmed
AhmedOP14mo 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
Accord14mo ago
Closed!
Sweerpotato
Sweerpotato14mo ago
No description
Accord
Accord14mo 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.
Want results from more Discord servers?
Add your server