C
C#4w ago
blunt

✅ static, public, void

I'm new to C# and I was wondering if I were correct that static means you can use an object or method outside of the file you are coding in, public means you are able to use an object or a method outside of a specific class and void means you will not return anything in the method proceeded?
8 Replies
Angius
Angius4w ago
static means it's accessible without an instance You're mostly correct on public, since in case of classes it means the class is usable in other projects And you're spot-on on void
blunt
bluntOP4w ago
tysm an instance is when you call a variable from a class or something right?
Angius
Angius4w ago
class Foo
{
public static int One => 1;
public int Two => 2;
}
class Foo
{
public static int One => 1;
public int Two => 2;
}
Foo.One; // works
Foo.Two; // does not

var f = new Foo();
f.One; // does not work
f.Two; // works
Foo.One; // works
Foo.Two; // does not

var f = new Foo();
f.One; // does not work
f.Two; // works
blunt
bluntOP4w ago
definitly the most useful piece of information tysm bro how do u write in that embedded thingy on discord?
Angius
Angius4w ago
$code
MODiX
MODiX4w ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
blunt
bluntOP4w ago
alr ty
Angius
Angius4w ago
:Ok:
Want results from more Discord servers?
Add your server