This is your first visit inside The Matrix. Welcome!

The Matrix has you…

This place will take you into the mirage of learning C# programming language, without any previous coding experience being required

Follow the White Rabbit…█

Close
Wednesday, September 20, 2017 16:30

Posts Tagged ‘variables’

Constants

Saturday, July 1st, 2017

Just like constants in mathematics, C# defines special fields of classes called constants. Like their name hints, once declared and initialized, constants maintain their values, forbidding their further modification.

There are two types of constants:

  • constants for which the value is set during the compilation (compile time constants)
  • constants which have their value set during the execution (run-time constants)

Compile time constants are declared using the C# modifier const:

[<access_modifiers>] const <type> <name>;

A secret not many C# programmers know is that compile time constants are static fields, even if they do not contain the static keyword, and the compiler forbids its usage in the declaration.… Read more

Variable Scope

Saturday, April 15th, 2017

A very important concept in programming is what we call variable scope. Though this concept should have been explained when I explained variables, it wouldn’t have made much sense back then, because it was relying on stuff we did not yet explain.… Read more

Value and reference types

Tuesday, January 3rd, 2017

Variables in C# can be categorized in two main types: value and reference types. What is the difference between them?

Value types are stored in a special area which is called the execution stack and their value is directly stored and accessed.… Read more

Nullable variable types

Thursday, December 29th, 2016

You may have noticed already that some variables can have a default value of null, while others can’t. Well, that is not entirely true. Nullable variable types refers to exactly this situation: creating a specific wrapper around the value types (types that cannot be null), that allow them to store data with a null value.… Read more

Object variable type

Thursday, December 29th, 2016

Object variable type is a special type, the parent of all other types in the .NET Framework. It can accept values from any other type in C#, and we declare it using the word object. 

In the following example you can see how we can assign any type to an object variable type:

// Declare some variables 
object container1 = 5; 
object container2 = "Five";

// Print the results on the console 
Console.WriteLine("The value of container1 is: " + container1); 
Console.WriteLine("The value of container2 is: " + container2);
Console.Read();

And the output would be:

object variable type

As you can notice, the object variable can be very versatile, and we can use it as a universal data container.… Read more

String variable type

Thursday, December 29th, 2016

If you remember the lesson about char variable type, you know that a char can only store a single character. And you also remember that for storing more than a single character, I said you will be using the string variable type.… Read more

Boolean variable type

Thursday, December 29th, 2016

The Boolean variable type is probably the easiest type of variable. It doesn’t have a “maximum range”, it can’t “overflow”, it’s not affected by precision, etc. In fact, Boolean variable type can only have two values: true  or false. They are almost exclusively used for calculations of logical expressions.… Read more

Real types error calculations

Thursday, December 29th, 2016

In calculations with real floating-point data types it is possible to observe strange behavior, because during the representation of a given real number it often happens to lose accuracy. The reason for this is the inability of some real numbers to be represented exactly as a sum of negative powers of the number 2.… Read more

Overflow exception

Wednesday, December 28th, 2016

You should already know by now that the type of a variable defines the interval of values that it can store and the operations that the software can execute upon them. An int type can store, for instance, values ranging from -2,147,483,648 to 2,147,483,647.… Read more

Type modifiers

Tuesday, December 27th, 2016

As you already learned, C# offers 6 base numeric types (int, byte, char, float, double, decimal). In order to explain type modifiers, you should remember that a type defines a set of values that a variable can store and the kind of operations that the program can perform on them.… Read more