How to Program in C# : Variables and Data Types (Part 2)

Variables and Data Types (Part 2)

Welcome back my friends !!

Today we'll go through the second part of this C# series
Let's start!!

Last time we left off with Console.WriteLine and Console.ReadKey now we'll combine these with some variables and comments.

Comments are useful for multiple reasons: for exemple they can help other developpers read your code or help you in case you

forgot what a line does or things like those.
Speaking of variables ...these are the 3 main data types of variables
(we'll see the rest of them as we procede into this series):
(EXEMPLES ARE DOWN THE LIST)

  • int (integers) : This variable defines only non-decimal numbers (like 1, 3, 4, 5, 259, 4000 etc...).
  • var : this is an implicit way of defining data types , unlike int or string (meaning ...in a indirect way or "generic" if you wish).
  • string : this variable only accepts text.

Here's an exemple of all 3 of them:(you may want to zoom in with your browser since it's quite small but everything's commented)

!!!!WARNING!!!!
always remember the " ; "(it's called "semi-colon") symbol at the end of the variables declaration line.
(There's a semi-colon at the end of every expression statement
and declaration statement, so you MUST NOT put the semi-colon at the end of every line)*

So...All types of variables can be "entered" or defined in 2 ways:

1) The first by first declaring the data type and then assign a value to the variable like this:

int x;
x = 2;

2) The second by declaring the data type and assigning the variable a value on the same line like this:

int x = 2;

Both of them are right.

That's all for now.
Thank you for reading

ThE-F1XeR

Just updated your iPhone? You'll find new features for Podcasts, News, Books, and TV, as well as important security improvements and fresh wallpapers. Find out what's new and changed on your iPhone with the iOS 17.5 update.

Be the First to Comment

Share Your Thoughts

  • Hot
  • Latest