C
C#2y ago
𝕯

❔ new to c# need help making new methods

how do i make a new method that works?
24 Replies
daniel2
daniel22y ago
U mean how to declare a method?
𝕯
𝕯OP2y ago
yea so like idk where to put the new mothod bc it gives a error when i make it
daniel2
daniel22y ago
Can I see the code?
𝕯
𝕯OP2y ago
yes how dod i send it in that format every1 uses wait nvm its ok using System; using System.Net; namespace Learning_Cs { internal class Program { static void Main(string[] args) { Console.WriteLine("Enter a username: "); string UserName = Console.ReadLine(); if (UserName.Length >= 3) { Console.WriteLine("Thats a short name"); }else { Console.WriteLine("Welcome in " + UserName); }
} } } so my goal is to make a method that loops asking for a username thats bigger than 3 letters
daniel2
daniel22y ago
U can use do loop
𝕯
𝕯OP2y ago
not yet still learing it learning*
daniel2
daniel22y ago
So
𝕯
𝕯OP2y ago
its in the vid im watching
Angius
Angius2y ago
To make code that loops... use a loop
𝕯
𝕯OP2y ago
bc with that code rn it works, but if the username is 3 letters or smaller i want it to continously ask for a bigger one right im tyrna make a method that loops
Angius
Angius2y ago
Methods don't loop
𝕯
𝕯OP2y ago
i want that if statement to call the method
Angius
Angius2y ago
Loops loop You can call a method inside of a loop, sure
𝕯
𝕯OP2y ago
oh well dam so do i make a loop with that if statement?
daniel2
daniel22y ago
String name; Do { name = console.ReadLine(); } While (name.Length <= 3)
arion
arion2y ago
while(condition)
{
}
while(condition)
{
}
daniel2
daniel22y ago
Maybe this will work
MODiX
MODiX2y ago
angius
REPL Result: Success
void Yell() {
Console.WriteLine("AAAAAAAAAAAAA!!!");
}

for (int i = 0; i < 10; i++) {
Yell();
}
void Yell() {
Console.WriteLine("AAAAAAAAAAAAA!!!");
}

for (int i = 0; i < 10; i++) {
Yell();
}
Console Output
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
AAAAAAAAAAAAA!!!
Compile: 636.571ms | Execution: 58.032ms | React with ❌ to remove this embed.
Angius
Angius2y ago
And, yeah, this would be the way
𝕯
𝕯OP2y ago
i dont understand that where would i put that at?
Angius
Angius2y ago
Wherever you want to ask for the user's name
daniel2
daniel22y ago
Do { something } then check condition, if true, keep doing things inside do {} until conditions is false This is do loop does
𝕯
𝕯OP2y ago
ahhhh okkk just gotta figure that out know i get it ty
Accord
Accord2y 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