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
Have you tried reading the errors?
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
You aren't
return
ing anythingIf a method has a return type that isn't
void
, it needs to return something of that type
Simpleok, i am stupid and forgot that 🙂
fixed the error
but i still got one in the first screenshot
And what does that error say?
can't convert the method group "PedirFrase" to the non-delegated type "string" did you try to call the method?
You need to call that method
Not just state its name
and how i do it?
Like with any other method call
There's 6 method calls in your code already, so you should know how to do it
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
in VerFrase() how can i refeer to the string i made in the first one
$scopes
thing a
is available in scope A
and scope B
thing b
is available only in scope B
frase
exists only in PedirFrase()
methodOk, so to see it I should store it in another variable?
so i can use it with the others funcionts
You could call this method, and use what it returns
The same way you use what
Console.ReadLine()
returnsYes, 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.
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 mainI don't understand what you mean here sorry 🙂
Are you familiar with parameters?
Console.WriteLine()
takes a string as a parameter
Your method can, similarly, take some parametersnot 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
I would suggest going through $helloworld, which will introduce you to these concepts
Written interactive course https://learn.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
Videos https://dotnet.microsoft.com/learn/videos
VerFrase(frase)
right?
That's the idea
ty
Thank you for your patience and response, I really appreciate it
yw
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
and this is main
You modify
frase
, but never return the new valueHow do I return it? I mean, if I type return, it asks me to modify other things
i mean
Well, modify those other things
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.
Do you actually get it?
string newString = YourMethod(oldString);
?did it now and it works 🙂
I'm getting the hang of it, it's a bit of a mess but it's great.