One of the common questions I always find myself asking an SWE is, “how do you know so many languages?” The response is always mixed with a joke or two. After spending time building full-stack applications using JavaScript with Ruby on Rails backend, I wanted to explore another backend framework that I am always seeing on job descriptions. .Net is a common framework that companies still use today. Until recently with JS and React, .net is normally connected with C#. So I wanted to dive deeper into the language and what difference/similarity does it have with JavaScript.

Print to the CMD

Let’s start with printing out an output to the CMD. In JavaScript, we can write our function and use console.log() to get our output. In C## we write Console.WriteLine(“Hello World”); to execute the output. However, C## will terminate the program once the line is executed. In order to keep the window up, we write another line of code: Console.ReadLine(); This will now leave the window open until you click Enter. This tells the program that we are done.

Please note: You need to include ‘;’ at the end of each line in C## so it can execute.

Variables

Javascript we know we need to declare any data type using ‘var’, ‘const’, and ‘let’. Today, we taught to avoid using var since const and let came out with ES6. Let’s use a classmate’s name and their age and declare the variable. In JS, we can use let for the age of the classmate. We use ‘let’ because we can update the age as our program progress in time. We can use ‘const’ for the name because a person’s name is generally not changed. In C#, use the word of the data type. For example, we use string to declare the variable name of ‘classmateName’ and int, for number, to declare ‘classmateAge’. With great powers, comes great responsibilities. Now that we know how to declare variables for name and age, we can use these variables to interpolate in our program.

#c-sharp-programming #javascript #learning #software-development

Understanding the Fundamentals of C# With a JS Background
1.10 GEEK