Jun 13, 2025 06:05 PM
(This post was last modified: Jun 18, 2025 07:58 AM by padrino.)
Introduction
Welcome to part 2 of Padrino's Tutorials. In this series I will be giving you the rundown on the fundementals you need to get started on your programming journey. We'll be using C# in this series, but the skills are transferable and you will be able to take what you learn and apply it to other languages. If you missed part 1, you should read it here. In part 2, we will be going over variables and data types, essential to understadn if you want to start building your own programs. So, let's get into it.
What is a variable?
Well, put simply, a variable is a way of storing data that we can access and use later in our program. In fact, you have already dipped your toe into using variables in our previous tutorial when we saved our users input and sent it back to them in our "hello, world!" program. But let's look at them some more examples
Above we can see a super simple declaration of a string variable. We declare a variable of type string, give it the name of name, and assign it the value of padrino. We can now access this in our program whenever we need to, for example, if we wanted to output it to the console we could do the following:
That code would give us the output of "padrino" in the console. So, pretty simple, hey? But in order to do more, we need to understand the different types of variables we can have, and in order to do that, we need to understand data types.
Data Types
Programming is all about data, we collect it, store it, manipulate it, and send it. But in order to do any of that we need to assign it to it's correct type. For example, if we tried to store the value "6" as a string in the way we did above, we could output it to the console no problem. But say we wanted to carry out some mathematical opperation on it, we would be met with an error. This is because the program sees that value as a string, not a number. So, what datatypes can we have? Let's look as some of the more fundemental ones you'll need:
String
A string is a string of characters that the program see's as pure text. Think of it as written language, something to be written or read. We signify a string by encolsing the value in double quotes. For example:
We can also carry out string opperations on this data type, but well get to that in another tutorial
Integer
An integer is a whole number. Unlike strings, we can carry out mathematical operations on Integers. Below you can see an example of us declaring 2 variables and multiplying them together and storing that value as a third integer:
Double
A double is very much like an integer, only we can use it to represent decimal values for example:
Char
A char is simply a single chracter enclosed in single quotes.
Boolean
A boolean is simply a true or false value. You will use this a lot to carry out checks in conditional statements - but we'll get to that later. Here's an example of them being declared:
Putting it into practice
Below I have written a simple program that uses many of the variable types mentioned above. Don't worry if you don't understand everything, it's a learning process - it's a lot to take in. I encourage you to mess around with it and try it yourself.
You can run this program on your visual studio install, or alternatievely you can use dotnetfiddle here.
You'll see that this code will output the following:
Conclusion
In this thread we have covered the basics of variables and data types and even put them into practice. Congratulations! This is a huge step in understanding the fndementals of prgramming - an again, don;t worry if you're struggling to understand, just keep at it. In the next installement we will cover some more complex operations such as loops and conditionals (one of which we I actually used in the code above, see if you can spot it!). As always, my DM's are always open if you need help understanding anything.
Welcome to part 2 of Padrino's Tutorials. In this series I will be giving you the rundown on the fundementals you need to get started on your programming journey. We'll be using C# in this series, but the skills are transferable and you will be able to take what you learn and apply it to other languages. If you missed part 1, you should read it here. In part 2, we will be going over variables and data types, essential to understadn if you want to start building your own programs. So, let's get into it.
What is a variable?
Well, put simply, a variable is a way of storing data that we can access and use later in our program. In fact, you have already dipped your toe into using variables in our previous tutorial when we saved our users input and sent it back to them in our "hello, world!" program. But let's look at them some more examples
Above we can see a super simple declaration of a string variable. We declare a variable of type string, give it the name of name, and assign it the value of padrino. We can now access this in our program whenever we need to, for example, if we wanted to output it to the console we could do the following:
Code
string name = "padrino";
Console.WriteLine(name);That code would give us the output of "padrino" in the console. So, pretty simple, hey? But in order to do more, we need to understand the different types of variables we can have, and in order to do that, we need to understand data types.
Data Types
Programming is all about data, we collect it, store it, manipulate it, and send it. But in order to do any of that we need to assign it to it's correct type. For example, if we tried to store the value "6" as a string in the way we did above, we could output it to the console no problem. But say we wanted to carry out some mathematical opperation on it, we would be met with an error. This is because the program sees that value as a string, not a number. So, what datatypes can we have? Let's look as some of the more fundemental ones you'll need:
String
A string is a string of characters that the program see's as pure text. Think of it as written language, something to be written or read. We signify a string by encolsing the value in double quotes. For example:
Code
String example = "this is a string";Integer
An integer is a whole number. Unlike strings, we can carry out mathematical operations on Integers. Below you can see an example of us declaring 2 variables and multiplying them together and storing that value as a third integer:
Code
Int myFirstInteger = 6;
Int mySecondInteger = 2;
Int myThirdInteger = myFirstInteger * mySecondInteger;Double
A double is very much like an integer, only we can use it to represent decimal values for example:
Code
Double myDouble = 6.66D;Char
A char is simply a single chracter enclosed in single quotes.
Code
char myChar = 'a';Boolean
A boolean is simply a true or false value. You will use this a lot to carry out checks in conditional statements - but we'll get to that later. Here's an example of them being declared:
Code
bool example = true;
bool anotherExample = false;Putting it into practice
Below I have written a simple program that uses many of the variable types mentioned above. Don't worry if you don't understand everything, it's a learning process - it's a lot to take in. I encourage you to mess around with it and try it yourself.
You can run this program on your visual studio install, or alternatievely you can use dotnetfiddle here.
Code
using System;
public class Program
{
public static void Main()
{
//strings
string name = "padrino";
Console.WriteLine(name);
//Characters
char character = 'p';
Console.WriteLine(character);
//Integers
int myFirstInteger = 6;
int mySecondInteger = 2;
int myThirdInteger = myFirstInteger * mySecondInteger;
Console.WriteLine(myThirdInteger);
//Boolean
bool example = true;
if(example){
Console.WriteLine("looks like the boolean was true.");
}
}
}You'll see that this code will output the following:
Code
padrino
p
12
looks like it was true.Conclusion
In this thread we have covered the basics of variables and data types and even put them into practice. Congratulations! This is a huge step in understanding the fndementals of prgramming - an again, don;t worry if you're struggling to understand, just keep at it. In the next installement we will cover some more complex operations such as loops and conditionals (one of which we I actually used in the code above, see if you can spot it!). As always, my DM's are always open if you need help understanding anything.



