Why can't I create a string in function and the | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why can't I create a string in function and the

Heii, I'm currently trying to write some code that returns a number (°C) to the function and a string that returns the aggregate state. Why can't I create a string in function and send it back. I have constantly in the back of my mind that the string "name" causes errors https://code.sololearn.com/cA12A10A12a2/?ref=app

11th Jun 2021, 3:50 PM
Shiko
Shiko - avatar
3 Answers
+ 2
the function call from main is returning a string but you are trying to store in int variable and The function is a non-static function. You have to call that by an instance or object of the class... This will fit there.... string name = new Temperatur().MesseZustand(temperatur); Console.Write(name);
11th Jun 2021, 4:13 PM
Jayakrishna 🇮🇳
+ 3
You are trying to store a string in an int variable in the following code, int name = MesseZustand(temperatur); Instead use "string name=.. " you can't call a non static method without creating an object of class and then calling the method on that object . If you don't want to do that , make the public string method static , public static string ..
11th Jun 2021, 4:12 PM
Abhay
Abhay - avatar
+ 1
MesseZustand is part of the Temperatur class. You need to create a instance of that class to be able to use that its method https://code.sololearn.com/c7Vjc00K96Lk/?ref=app
11th Jun 2021, 4:12 PM
sneeze
sneeze - avatar