C
C#•2y ago
AriieSiiS

Idk how class works

I'm working with creating the functions in a separate file, so I wanted to create a function that would ask for a phrase and save it as a string, and call it from my "main" to work with that, but I don't know what I'm doing wrong exactly.
43 Replies
AriieSiiS
AriieSiiSOP•2y ago
333fred
333fred•2y ago
Have you tried reading the errors?
AriieSiiS
AriieSiiSOP•2y ago
Yes but I don't understand what it means, I get "not all paths return a value". in this screenshot . and in the first one
333fred
333fred•2y ago
You aren't returning anything
Angius
Angius•2y ago
If a method has a return type that isn't void, it needs to return something of that type Simple
AriieSiiS
AriieSiiSOP•2y ago
ok, i am stupid and forgot that 🙂 fixed the error but i still got one in the first screenshot
333fred
333fred•2y ago
And what does that error say?
AriieSiiS
AriieSiiSOP•2y ago
can't convert the method group "PedirFrase" to the non-delegated type "string" did you try to call the method?
Angius
Angius•2y ago
You need to call that method Not just state its name
AriieSiiS
AriieSiiSOP•2y ago
and how i do it?
Angius
Angius•2y ago
Like with any other method call There's 6 method calls in your code already, so you should know how to do it
AriieSiiS
AriieSiiSOP•2y ago
writing () ? I've tried it and that's what it is, although I don't really understand it at all. i.e. I didn't know that to do so I had to put () obligatorily but ty 🙂 sorry for my noob questions trying to understand things
AriieSiiS
AriieSiiSOP•2y ago
AriieSiiS
AriieSiiSOP•2y ago
in VerFrase() how can i refeer to the string i made in the first one
Angius
Angius•2y ago
$scopes
MODiX
MODiX•2y ago
scope A {
thing a;
scope B {
thing b;
}
}
scope A {
thing a;
scope B {
thing b;
}
}
thing a is available in scope A and scope B thing b is available only in scope B
Angius
Angius•2y ago
frase exists only in PedirFrase() method
AriieSiiS
AriieSiiSOP•2y ago
Ok, so to see it I should store it in another variable? so i can use it with the others funcionts
Angius
Angius•2y ago
You could call this method, and use what it returns The same way you use what Console.ReadLine() returns
AriieSiiS
AriieSiiSOP•2y ago
Yes, but I already call it in the main, so when I call it again it asks me to write the string again, and I want to continue working with the string I picked up the first time.
Angius
Angius•2y ago
Well, you can make VerFrase() take a string Then you would get the string in the main, and then you'd pass it to VerFrase(), also in the main
AriieSiiS
AriieSiiSOP•2y ago
I don't understand what you mean here sorry 🙂
333fred
333fred•2y ago
Are you familiar with parameters?
Angius
Angius•2y ago
Console.WriteLine() takes a string as a parameter Your method can, similarly, take some parameters
333fred
333fred•2y ago
Did you mean WriteLine?
AriieSiiS
AriieSiiSOP•2y ago
not too much, i mean probably yes, but I don't know, until today I had only worked on the "main" doing exercises, so I'm getting a bit confused with the whole topic of functions, methods, calls, etc. but I think I know what you are saying
333fred
333fred•2y ago
I would suggest going through $helloworld, which will introduce you to these concepts
AriieSiiS
AriieSiiSOP•2y ago
VerFrase(frase) right?
333fred
333fred•2y ago
That's the idea
AriieSiiS
AriieSiiSOP•2y ago
AriieSiiS
AriieSiiSOP•2y ago
ty Thank you for your patience and response, I really appreciate it
333fred
333fred•2y ago
yw
AriieSiiS
AriieSiiSOP•2y ago
I have another question, now I'm trying to add a letter to the string I ask for, and everything is fine, the problem is that when I go back to Main, the string recovers its value before entering the function that adds a letter, I don't know if I'm explaining myself
AriieSiiS
AriieSiiSOP•2y ago
AriieSiiS
AriieSiiSOP•2y ago
and this is main
Angius
Angius•2y ago
You modify frase, but never return the new value
AriieSiiS
AriieSiiSOP•2y ago
How do I return it? I mean, if I type return, it asks me to modify other things i mean
Angius
Angius•2y ago
Well, modify those other things
AriieSiiS
AriieSiiSOP•2y ago
nevermind i was writing in another line, thats why ty 🙂 ok, it still doesn't work, it has no errors or anything, and I have put the return, but I don't get the new concatenated string.
Angius
Angius•2y ago
Do you actually get it? string newString = YourMethod(oldString);?
AriieSiiS
AriieSiiSOP•2y ago
did it now and it works 🙂
AriieSiiS
AriieSiiSOP•2y ago
I'm getting the hang of it, it's a bit of a mess but it's great.
Want results from more Discord servers?
Add your server