Variables in C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Variables in C#

Please explain variables in depth

31st May 2017, 5:24 AM
Nayan pachori
Nayan pachori - avatar
4 Answers
+ 2
Easy! //var "var" is the lazy man of variables. If you're unsure what type of value an output will produce, then using "var" will have the compiler decide what variable is best fitted for the output. Though it is microscopically slower than all other types, so avoid using this unless absolutely needed. //float In a Visual Studio based environment, these are useless, as they only hold 7 numbers and a decimal. However, in engines like Unity, you will be forced to use these ALL the time. //double The big brother of "float", a double can hold a max of (if I remember correctly) 16 numbers, along with a decimal. It allows for VERY precise numbers, in fact the real name of a double is a double precision float. //int An "int" is your average Joe. Allowing you to use any whole number you please, and is the most basic value type for numbers. //string You will be forced to work with these monsters a TON. A string allows a long sequence of characters to either be displayed or manipulated, while also giving the possibility to convert them out to other value types. //char Short for character, this variable is fairly useless alone, only allowing a max of one character. Do note though, that these will become useful in advanced manipulation of strings. //bool A boolean, my favorite kind of variable. Booleans work by accepting a true or false output. No matter what you get into, the bool will almost always be used. So DEFINITELY remember how to use these. I hope this helps not only you, but everyone else who needed help on these. If you have any further questions, feel free to ask me.
31st May 2017, 6:12 AM
_Meowz_
_Meowz_ - avatar
+ 2
Dont forget byte and sbyte, very useful for saving memory if you are storing small numbers or doing something directly related to memory IntPtr and UIntPtr are also useful for storing pointers or handles
31st May 2017, 7:14 AM
aklex
aklex - avatar
0
Thank you :)
31st May 2017, 6:15 AM
Nayan pachori
Nayan pachori - avatar
0
and int8,int32 etc?
31st May 2017, 7:34 AM
Nayan pachori
Nayan pachori - avatar