0
Variables.
Hi everyone. I just took the c# course on variables but I am unsure how I should insert the Console.WriteLine (variable) code into my program. (My apologies for any confusion I was not sure how to write the question. If there is any confusion please let me know so I can explain in more depth. )
3 Réponses
+ 4
Looking at your profile, it seems like you have your code working. You should put your codes inside the main() function.
you can trim it down a bit though.
using System;
// Delete these. You don't need them yet.
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
namespace Sololearn
{
class Program
{
static void Main(string[] args)
{
// define and initialize your variable
string alphabet = "abcdefghijklmnopqrstuvwxyz";
// use your variable
Console.WriteLine(alphabet);
}
}
}
+ 3
And for future reference, please read these, it'll allow others to help you more easily:
https://sololearn.com/compiler-playground/Wek0V1MyIR2r/?ref=app
https://sololearn.com/compiler-playground/WZ8lkR6gTex6/?ref=app
https://sololearn.com/compiler-playground/W3uiji9X28C1/?ref=app
https://sololearn.com/compiler-playground/W0uW3Wks8UBk/?ref=app
0
At the beggining, write everything into Main method. You will learn soon about other ways, but bother with it now
//premade codes
static void Main(string[] args)
{
//your whole program is here for now
//give to WriteLine what it should write directly
Console.WriteLine("This will be writen without variable");
//declaring a variable
string variable="This is a variable i made";
//give to WriteLine method a variable to output
Console.WriteLine(variable);
//declaring another variable, number this time
int x=5;
//again, give it a string directly
Console.Writeline("On next line will output variable x");
//again, WriteLine will output variable's value
Console.WriteLine(x);
}
//this is out of Main method, will make error
Console.WriteLine("This will make error");