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. )

27th Jan 2025, 1:26 AM
Tyler
3 Respuestas
+ 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); } } }
27th Jan 2025, 2:39 AM
Bob_Li
Bob_Li - avatar
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");
28th Jan 2025, 9:18 PM
Jarda Václavík
Jarda Václavík - avatar