int and string are data types or variables. int stands for integer and means it sorta needs a number value. Not just any number, it needs to be a....full number, as in no decimals. string on the other hand is a....text type....sort of.
Console.Write() and Console.WriteLine() outputs whatever you put in the brackets, while WriteLine puts it on a brand new line.
Console.ReadLine() requires the user to input something, anything really. Well...I say anything, but if you don't put in whatever the program asks you to put in, you might not get far.
Both of these are string types, which means that they output text or reads whatever you put in there as....well...a string. This usually isn't a problem for the WriteLine because it only outputs what you decided it should output. But if you put a number in the ReadLine then the console is going to treat it as text, which again, isn't a problem unless you want the program to calculate. The program does not understand how to calculate letters (which, let's be honest, neither do I). So to change the text input into numbers we have to parse it by coding, for example, iLuku = int.Parse(luku) which basically means that the luku string (whatever you input in that ReadLine) will be changed into iLuku int type. From now on you need to use iLuku in your calculations, since thats a real number, while luku is just a text (even in number format).
However, since we decided that that ReadLine needs a number, the program will complain and crash if you DON'T put in a number. It doesn't want to deal with text in that one. So what we do is make a try-catch...thing? statement? to make sure that the program does something if people don't write what we want them to write. This is done by coding (as an example) the following segment:
try
{
Console.Write(luku);
iLuku = int.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("You didn't give the correct value!");
}
This means that the program will check whatever you write in the Console.ReadLine slot and if anything at all goes wrong (in this case, you not writing the correct number) it will move on to the catch block and run whatever commands is in there (in this case it will just tell you that you didn't give the correct value) and then move on to the next part of the program.
If whatever you need to input is crucial for the program to function, we might as well put in a loop to make sure that we WILL be getting some form of proper value. For that we need a Boolean variable and the boolean will need a name and a start value that is either false or true. What I understood is that it's best to start with a false value? Maybe you have to to start as a false? Maybe not, I'm not really sure, we've always started with a false. So the code will look something like this instead:
Boolean ok = false;
while (ok == false)
{try
{
Console.Write(luku);
iLuku = int.Parse(Console.ReadLine());
ok = true;
}
catch
{
Console.WriteLine("You didn't give the correct value!");
ok = false;
}
}
Now the program will loop and loop and loop until ok turns true, and ok only turns true if you put in a proper number. Take that rebels!
Ok so that's about as much as I want to write now, I've learned a lot more but I don't want to make too long a post and too big of an ass of myself in case all I've learned is false. I would appreciate it if you'd correct me if I understood something wrong. I wouldn't want to continue being wrong.