C#; JS Comparison and Game Dev.
Tags: programming, csharp, gamedev, career
Published: 2023-02-13 06:07:33

## Intro
As a beginner in software and coding, one of my biggest passions/obsessions is my love for video games. Now that I'm tackling JS coding, my interest in becoming a game developer has increased. This is where a new question comes in. What language is the best for getting into game development? To answer that question, we have to look at the topic of today's discussion, C#.

C# (C Sharp), is a programming language built in Microsoft's .NET Framework. The following are some key concept about the link between .NET and C#, as well as some other useful info on C#:

- .NET (dot net) is a library of built methods, security checks, and compiler commands that translate code from other languages into one readable language before execution. EX: C, C++, Java.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84g5irylh7s98olbnr5v.png)

- C# itself is object-oriented, meaning that every variable and expression declaration has to be tied to an object or method. In JS, this is called Class construction which follows a similar pattern.

```
class Program {
void print(int i, int j) {
Console.WriteLine("Printing int: {0}", (i+j) );
}
void print(string a, string b) {
Console.WriteLine("Printing String: " , (a+b));
}
       
static void Main(string[] args) {
Program prog = new Program();
          
// Call print for sum of integers
prog.print(5, 6);
          
// Call to concatenate strings
prog.print("Hello","World");
Console.ReadKey();
}
}

//source: https://www.softwaretestinghelp.com/c-sharp/oops-concepts-in-csharp/
```

- C# is strongly typed; meaning that any expression declaration, any object, or string reference has to mean exactly what it is tied to. _EX: `{int = i;}` => this is an integer declaration with i representing a number._

- Whereas JavaScript is single-threaded, C# is multi-threaded.

> This refers to the number of simultaneous connections we use when running our speed tests.
> "Single-threaded" means that we open a single connection and measure the speeds from that.
> "Multi-threaded" means that we're using multiple connections - usually anywhere from 3 to 8 - at the same time, and measure the total speed across them all.

[source](https://samknows.one/hc/en-gb/articles/115003164305-What-is-the-difference-between-Single-and-Multi-Thread-)

## JS vs (C#)
The difference between C# and JavaScript, while vast, mainly comes down to how each snippet of code is build and executed. Take for example the following code snippets.

- JS

```
const newNumber = 'Hello World';                          
 const print = (str) => {
   console.log(str);
 }
 print(newNumber);
```

- C#

```
using System;

 namespace addingNumbers
 {
   class Program
   {
     static void Main(string[] args)
     {
       Console.WriteLine("Hello World!");    
     }
   }
 }
```
**Example one** shows us a JS code snippet that has variables declared outside the object `const newNumber = 'Hello World';`, a function built to print a string to the console `const print = (str) => {
   console.log(str);
 }`, and the invocation of said function passing in our string variable `print(newNumber);`. 

**Example two** shows us a C# code snippet. The first line `using System` is referencing the current environment that is being used to build the code. The next line of code `namespace addingNumbers
` references separation of code blocks in the file. Next we have our class creation `class Program` where the code we want to execute will be written. The `static` class designation assigns the variable to the class object and only that object. `Void` lets the method know that it won't be returning any value. `Main` is the starting point of the method, and the variables are passing in our parameters. What we have left is a console print `Console.WriteLine("Hello World!")`, similar to a console log.

A lot of information was presented, but to put it simply both these snippets do the same thing. The big difference is that class creation is needed to get the end result in C#, whereas in JS you can build and execute outside of a class.

##C# Apps

![Unity](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhx2hok2sco254ubrswo.jpg)

Now with all of that being said, what kind of applications use C#? Web Apps, Workflow apps, and Windows Services. There is of course one more use of C#; Game Development. C# is the backbone of many different gaming engines including Unity and CryEngine. While I would explain the key features of each, for now I'll leave it for another blog.

![CryEngine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cd7sy4bcp4kp0cjca71u.jpg)

## Conclusion

My small time researching C# has opened my eyes to how terrifying at first it is to understand a different language. I hope to explore more C# as I continue to climb towards becoming a Game Developer.