Having a deep understanding of Javascript can leave you hungry for more knowledge. What other languages could one learn to diversify their skillset? If one is especially interested in game design, like the author, one would need to learn a language that is the most compatible. While Javascript is a powerful language that can make some fun games, it seems the industry leans towards C#. In this blog, we will assume you have a working knowledge of JavaScript as we take a closer look at C#.
It all starts with C. C is a general-purpose programming language that was created in 1972.
Then came C++. Released in 1985, it is a faster, yet more complex object-oriented programming language
In 1999, Anders Hejlsberg made a team to build a new Language for Microsoft called Cool (C-like Object Oriented Language)
Microsoft decided to drop the Cool name for trademark reasons and shift to C#. It is a reference to the C language and some wordplay on C++. You can view the pound sign as four interconnected pluses (C++++)
Syntax
Data Types
Let's take a closer look at what types of data C# uses and how to declare them. In C#, a variable stores a specific data type value. You can declare/assign a value to a variable by int y = 10. Int is the data type, y is the variable name and the = assignment operator that points at the value 10. Here are some more examples:
//<data type> <var name> = <value> ;
int num = 101;
float rate = 6.2f; // floating point, only fills at least 6
//character spaces (including the decimal separator), with
//exactly 2 digits after the ".", padded with empty space.
decimal amount = 5.5M;
char code = 'C'; //singe quotes for characters
string name = "James"; //double quotes for strings
bool isInformative = true;
C# also has complex data types similar to Javascript. Arrays are still zero-indexed, the elements can be of any type, including Arrays. They are declared by 'data type' [] 'name' = 'array'.
//Declare a single-dimensional array of 4 integers
int [] array1 = new int[4];
//Declare and set array element values
int [] array2 = [1, 2, 3, 4];
//for more than one data type Object is the data type
Object[] mixedArray = new Object[] {1, '2', 3, 'A', true};
Class and Objects
A class is a blueprint of a particular object that has certain attributes. Take the famous example of a car. It should have attributes like wheels, doors, mirrors, etc. It should also have some functions like acceleration and braking. Any object that has these functions and attributes is a car. In this example, a car is a defining class. Each single car is an object of the car class. The car you own is an object of the car class.
class Car
{
// a private field that cannot be accessed directly.
private int id;
//only accessed with the public property
public int CarId
{
get { return id; } //returns value of id field
set { id = value} // assigns value to field id
}
}
Printing to Console
Similar to JS, there is a Console function, but there are two types:
//Console.Write() prints data without printing a new line
Console.Write("C#");
Console.Write("is");
Console.Write("fun");
//output C#isfun
//Console.WriteLine() prints data along with a new line
Console.WriteLine("C#");
Console.WriteLine("is");
Console.WriteLine("fun");
//output
C#
is
fun
Uses
C# can be used in many applications, but some of the more popular ones Windows programs, Cloud Backend services like Azure and game design. As a developer who is highly interested in game design, C# is one of the languages I want to understand better. It is a robust language that is useful in game creation as it has the infrastructure built for it already. From a practical standpoint, as a game developer, chances are you will not write a game engine from scratch. That would take way too much time and the learning curve is steep. A game dev would more than likely use a pre-existing mainstream engine such as Unity, CryEngine, or Godot. These engines come fully developed with robust features and use C# as the main language for logic and implementation. C# is programmer-friendly and has efficient performance uses.
In Conclusion
I hope this blog has inspired you to look deeper into the wonderful world of C#. Its learning accessibility, computing power, and a myriad of applications make it an attractive choice for developers who want to take the next step of their Polyglot Journey. Check out my references to dive deeper and stay Sharp out there. See?
References
https://en.wikipedia.org/wiki/C_Sharp_(programming_language)#
https://www.mygreatlearning.com/blog/difference-between-c-and-c/#
https://narrasoft.com/top-c-sharp-game-engines/
https://www.tutorialsteacher.com/csharp/csharp-variable
https://www.geeksforgeeks.org/difference-between-console-write-and-console-writeline-in-c-sharp/
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/arrays
https://www.tutorialsteacher.com/csharp/csharp-class
Top comments (0)