✅ Hi this is my code and what ive done so far

my code: https://paste.mod.gg/jqrupyuavvys/0 this is what ive done and some of it cant get to work im not new to programming im just no so good with it. Thanks!
BlazeBin - jqrupyuavvys
A tool for sharing your source code with the world!
No description
20 Replies
Angius
Angius2mo ago
The error is quite clear askingForAge is a class You can't call a class The rest is just warnings
Jexs(ping me)
Jexs(ping me)OP2mo ago
Oh
Angius
Angius2mo ago
All of them, still, perfectly clear, so you should have no issues clearing them either
Jexs(ping me)
Jexs(ping me)OP2mo ago
Thank you ZZZ ! ill try that now !
Jexs(ping me)
Jexs(ping me)OP2mo ago
i did something like AskforAge.AskForage and no go?
No description
Angius
Angius2mo ago
Does askingForAge class have an AskForAge method? C# is case-sensitive, remember Also, is that method static?
Jexs(ping me)
Jexs(ping me)OP2mo ago
isnt that the method? also from what i know so far static (from a video i saw) means you can use it once i guess?
No description
Angius
Angius2mo ago
No description
Angius
Angius2mo ago
No description
Jexs(ping me)
Jexs(ping me)OP2mo ago
oh !
Angius
Angius2mo ago
No description
Jexs(ping me)
Jexs(ping me)OP2mo ago
okay! why does static matter im not using them in my classes methods ?
Angius
Angius2mo ago
A non-static method needs an instance of the class So, sure, if you want it can just be non-static But you will need an instance
Jexs(ping me)
Jexs(ping me)OP2mo ago
give me one sec looking into static
Jexs(ping me)
Jexs(ping me)OP2mo ago
Access Modifiers - C#
All types and type members in C# have an accessibility level that controls whether they can be used from other code. Review this list of access modifiers.
Jexs(ping me)
Jexs(ping me)OP2mo ago
is this for security reasons ?
No description
Jexs(ping me)
Jexs(ping me)OP2mo ago
oh shit that was an ai responce Would static go to something like let’s say there’s a blue team and a red team there both different teams right so something unique ?
Pobiega
Pobiega2mo ago
The AI response is entirely correct here, and your team analogy doesn't really make sense to me. its also not an access modifier it has to do with object instances and "ownership" a static method or field belongs to the class itself, not an instance of it, unlike a non-static one which belongs to an instance
var a = new Holder();
var b = new Holder();

a.Add(5);
b.Add(10);

Console.WriteLine($"{a.Count} | {b.Count} | {Holder.TotalCount}");

public class Holder
{
// This one belongs to the instance
public int Count { get; private set; }

// This one belongs to the class itself
public static int TotalCount { get; private set; }

public void Add(int i)
{
// increase BOTH properties
Count += i;
TotalCount += i;
}
}
var a = new Holder();
var b = new Holder();

a.Add(5);
b.Add(10);

Console.WriteLine($"{a.Count} | {b.Count} | {Holder.TotalCount}");

public class Holder
{
// This one belongs to the instance
public int Count { get; private set; }

// This one belongs to the class itself
public static int TotalCount { get; private set; }

public void Add(int i)
{
// increase BOTH properties
Count += i;
TotalCount += i;
}
}
look at this example. What do you think it will print when ran? @Jexs(ping me)
Jexs(ping me)
Jexs(ping me)OP2mo ago
uh 6 and 11? oh wait 6,11,15?
Pobiega
Pobiega2mo ago
5, 10, 15 int defaults to 0, not 1 pay attention to how the values are accessed, ie a.Count and Holder.TotalCount a doesn't have a .TotalCount, and Holder doesn't have a .Count

Did you find this page helpful?