16th May 2018, 5:56 PM
Arjun
Arjun - avatar
13 ответов
+ 4
@Arjun https://code.sololearn.com/cJCzMQ7EW25W/#cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string YourName = ""; string a = "Arjun"; YourName = Console.ReadLine(); if (YourName == a) { Console.WriteLine("Hello, {0}!", YourName); } else { Console.WriteLine("Please try again, {0}.", YourName); } } } }
16th May 2018, 6:05 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 3
:::ERROR::: ..\Playground\(15,24): error CS0103: The name 'a' does not exist in the current context ^As advised in your compilation error, you never declared the variable 'a'. Simply declare the variable and you'll be able to utilize it or use a string literal for comparison instead. Also,... CHANGE: if (YourName = a) TO: if (YourName == a) ^Currently, you have it ASSIGNING the value to the variable 'YourName'. However, I assume you were wanting to do a comparison instead. When doing a COMPARISON with the value, you'll want to use double-equals sign '=='.
16th May 2018, 6:02 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 3
Line 13: string YourName = ""; Line 14: string a = "Arjun"; Line 15: YourName = Console.ReadLine(); ^ Line 13 is where you declared your string variable 'YourName'. Line 14 is where we declared your string variable 'a'. Line 15 is where we assigned the user's input to our variable 'YourName'.
16th May 2018, 6:19 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 2
@Arjun As for why, the variables do NOT exist in memory until you declare them, which is why we declare them at the top BEFORE we use them below. Think of it like boxes. We can't put stuff into a box that doesn't even exist. However, if get a box and then put a piece of tape on it with a label of what the box is used for, that is like declaring a variable; we create a space in memory, label it with a name, and determine the type of data it'll hold.
16th May 2018, 6:22 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 1
thanks Fata1 Err0r ... can you explain the lines 13 14 15? why?
16th May 2018, 6:08 PM
Arjun
Arjun - avatar
16th May 2018, 6:09 PM
Rajeeb
+ 1
until var a is defined as string . compiler won't check for variable a it produce error , as no declaration
16th May 2018, 6:14 PM
Rajeeb
+ 1
thanks all
16th May 2018, 6:20 PM
Arjun
Arjun - avatar
0
define the string a
16th May 2018, 5:58 PM
Rajeeb
0
how
16th May 2018, 5:59 PM
Arjun
Arjun - avatar
0
string a = "a";
16th May 2018, 6:07 PM
Rajeeb
0
thanks Rajeeb can you elaborate the define the string a
16th May 2018, 6:13 PM
Arjun
Arjun - avatar
0
oh
16th May 2018, 6:23 PM
Arjun
Arjun - avatar