![]() |
|
[The Academy] Let's talk about variables - Padrino's Tutorials : Part 2 - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5) +---- Thread: [The Academy] Let's talk about variables - Padrino's Tutorials : Part 2 (/showthread.php?tid=6300314) |
Let's talk about variables - Padrino's Tutorials : Part 2 - padrino - Jun 13, 2025 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: Code string name = "padrino";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;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;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;You'll see that this code will output the following: Code padrinoConclusion 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. RE: Let's talk about variables - Padrino's Tutorials : Part 2 - Bastille - Jun 14, 2025 Thanks for the turorial, can't wait to see concrete examples and applications, such as hiding processes, or making malware. |