I cant understand this | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I cant understand this

Fill in the blanks to ask for user input in the method and return the value entered using output parameters. static void Ask( out string name) { ???? = Console.ReadLine(); } static void Main(string[] args) { string nm; Ask( out nm); } What should be before Console.readline

21st Apr 2018, 11:38 PM
Hovhannes Harutyunyan
Hovhannes Harutyunyan - avatar
3 Answers
+ 3
Note that the Ask method has a return type of void, which means it doesn't actually return a value of any particular type from its method. Here the use of the out keyword is used when passing the argument to the method along with the declaration of the parameter so that the value of the objects address is passed and used within the Ask method so that it may assign the value using the alias 'name' within the Ask method to the nm variable that is passed in as the argument. static void Main(string[] args) { string nm; Ask(out nm); Console.WriteLine(nm); } static void Ask(out string name) { name = Console.ReadLine(); }
22nd Apr 2018, 1:12 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
variable declaration String name ; name=Console.ReadLine(); or String name=Console.ReadLine(); you ask the computer to save user input in this variable.
22nd Apr 2018, 12:13 AM
Ahmed Mohammed Ahmed Khodary
Ahmed Mohammed Ahmed Khodary - avatar
+ 1
thanks a lot
22nd Apr 2018, 6:17 AM
Hovhannes Harutyunyan
Hovhannes Harutyunyan - avatar