Results 1 to 9 of 9
  1. #1
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy

    [Repost] C# Beggining Tutorial by Brinuz (Continuation)

    C# Tutorial by: Brinuz @ MPGH.

    First of all, this is not C++!!! and this is not exactly the best language to make hacks, etc.

    Reposting because the old one (2 weeks older), I am now unable to edit it and add things like i said i would, this is why im Reposting, and Also, i request Why06 if he can change the link of the one in the C++ Tut List.
    Thanks everyone.

    Old one: https://www.mpgh.net/forum/31-c-c/104...s-keeping.html

    You need a compiler, i sugest: Visual C# 2008 Express Edition.
    You'll easly find it free to download and install.


    *Open it and let's create a project:


    • File -> New Project OR ...


    • Select Console Application
    • Call it w/e you want (Default: ConsoleApplication1)
    • Click Ok


    • There you go, a project for you to start with

    Ok, before starting to post Codes of lines and lines, you should know a few basic things to code:

    ---------*** Chapter:Getting Started ***---------


    This:
    // when you see something like this in the code, it means that the program will ignore it, its just a comment in the lines.

    OR

    /*when you see something like this in the code, it means that the program will ignore it, its just a comment in the lines. */

    ***************************

    *Every normal line of coding that contains an instruction should end with ";".

    e.g:
    Code:
    int var;
    string text;
    text = "www.mpgh.net";
    var = 1337;
    ***************************

    *Getting the past e.g, you should know what are the most basic data type in this language: String, Int.

    lets set it easy:

    -An Int is a "bit" of memory that is created, and used by the program that will let you save a number. (ATTENTION: NOT NUMBERS LIKE 1.3, or 1323.1256788, for that you shuld use the type: Double or Float).

    -A String is a "bit" of memory that is created, and used by the program that will let you save text, basiclly anything you write or set in it (this includes numbers, letters, symobols, etc).

    *Also when you create one:

    Code:
    string text;
    you can initialize it as a value, eg:

    Code:
    string text = "www.mpgh.net";
    but, lets say that you will only later what it will have, you can always do:

    Code:
    string text;
    
    //code
    //code
    //code
    //code
    
    text = "www.mpgh.net";
    *You can also "say" that a string is equal to another one:

    Code:
    string Text = "www.mpgh.net";
    string Link = Text;
    OR

    Code:
    string Text = "www.mpgh.net";
    string Link;
    Link = Text;

    *You can add one string to another:


    Code:
    string Site = "mpgh.net";
    string web = "www.";
    
    web = web + site; // this will add "www."+"mpgh.net", which will result in "www.mpgh.net"
    *You can do maths with data of the type int:

    Code:
    int x = 2;
    int y = 1;
    int result;
    
    result = x + y; //the value of result will be 3. which is 2 plus 1.

    ---------*** Chapter: Start ***---------


    Bla, bla bla... im here writing stuff and you will probabily don't understand without using it. (which may be normal, mainly because i can't explain myself that well, even if i know xD).
    Let's get into action and code something!

    Code:
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * 
     * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
     * C# Starting Tutorial and basics for MPGH by Brinuz. *
     * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    
    // Basiclly this contais objects that you might use later on your code like Console. the one beeing used in Main() (which makes you able to write on console)
    using System;
    
    // You will learn a bit more about this, but as you may realise this has the same name as you console application.
    namespace ConsoleApplication1
    {
        public class Program //your main Class, the body of you code. I will talk later about what is a class and how to use.
        {
            static void Main() //your main, your program will start #
            { 
                // # HERE and will finish always (or most of the times.... you may be able to close it, quit it at the middle of it, etc...) *
                
    	    string textWorld = " Hello World!"; //Explained it Before at the start of the post.
    
                Console.Write("The mighty message that everyone writes:");
                    // This is the basic mode of writing in Console: Console.Write(""); this will write a line with the text that you may insert in ("").
                Console.WriteLine(textWorld);
                    // This one does the same as the one before, but will add a line at the end of the line, so the next Console.Write(""); or w/e will be used in the next line.
    		// AND
    		// Instead of the need to write " Hello World!" thing, since you already have it saved in memory, you can use it. (textWorld)
                // * FINISH HERE
            }
        }
    }

    Ok, i guess you can see one or other thing that i tried to explain at the start, beeing used in there... You shouldnt really pay that much attention now to Class's, namespace, etc...

    *************************

    ---------*** Chapter: IF (Comparation) ***---------


    *Lets say you want to compare two or more things in your program, AGE, for example...

    you use;

    Code:
    if(condition)
    {
    }
    else
    {
    }
    condition Operators:

    > or < : Obvious?
    == : equals.
    != : different

    *you should do somethings like this:

    Code:
    using System;
    
    namespace ConsoleApplication1
    {
        public class Program
        {
            static void Main()
            {
                int a = 18;
                int b = 29;
    
                if (a > b) //this will compare 2 or more things (lets just stay with 2 for now...) it will check if a is bigger then b, and if it is, it will do:
                {
                    Console.WriteLine("var a is Older then var b"); //since a were older (or bigger) then b, it will execute every instruction inside this { ... }
                }
                else //if a isnt bigger then b, then he will do this (just like our language: If i'm a boy, i will like girls, Else i will like boys.
                {
                    Console.WriteLine("var a i Younger then var b");
                }
            }
        }
    }
    Of course this one wouldnt be that logic because you always know the values you insert at a and b, so you actually know which one is the older. Let's try another new thing:

    *You can read something that you type on console:

    Code:
    string Name = "";
    Console.WriteLine("Insert your name:");
    Name = Console.ReadLine(); //it will save what he read from your input in the var Name
    Console.WriteLine("Your name is " + Name);
    as simple as that. the string Name will get the value (or text) that you typed in the console and when Enter key is pressed.

    *Now getting this into a Program (using the old eg.)

    Code:
    using System;
    
    namespace ConsoleApplication1
    {
        public class Program
        {
            static void Main()
            {
                int a = 0;
                int b = 0;
    
                Console.WriteLine("Insert the age of the first person:");
                a = Convert.ToInt32(Console.ReadLine()); //i do have here to use Convert.ToInt32() in here because he will need to convert the type string (text, etc.) into a INT, so it has a better way to compare, or do mats, w/e.
                Console.WriteLine("Insert the age of the secound person:");
                b = Convert.ToInt32(Console.ReadLine());
    
                if (a > b) //this will compare 2 or more things (lets just stay with 2 for now...) it will check if a is bigger then b, and if it is, it will do:
                {
                    Console.WriteLine("var a is Older then var b"); //since a were older (or bigger) then b, it will execute every instruction inside this { ... }
                }
                else //if a isnt bigger then b, then he will do this (just like our language: If i'm a boy, i will like girls, Else i will like boys.
                {
                    Console.WriteLine("var a i Younger then var b");
                }
            }
        }
    }
    *Now that you know something already let's have something for you to do by urself or check:

    ---------*** Chapter: Something for you TO DO***---------


    Make a program that follow this:
    -Will ask a user to input 2 numbers
    -these numbers can't be the same
    -numbers must to be between 0 and 20.
    -at the end it will write in the console which number is the bigger and tell the difference between them.

    eg: if you insert 5 and 15... the difference would be 10... from 5 to 15.

    IMPORTANT!!! IF YOU REALLY WANT TO LEARN THIS BY URSELF, DO IT WITHOUT LOOKING TO THE SOLUTION WITHOUT THE PROGRAM BEEING FINISHED!!
    -You can check what you have read already.
    -You Shouldnt check the solution without finishing.
    -Try not to Copy&Paste old E.g's.[/CENTER]

    *i'm advicing you this, because it is the best way to learn something


    *One of the many possible Solutions:

    i will make this as simpler as possible for you to understand, but there is a thing that you need to be "aware", IT IS possible to make this in a simpler, and way better mode. I made it like this for a better understanding from others and you. Keep that in mind.


    Before posting the solution. I will talk to you about more operators:

    Code:
    ||
    and
    Code:
    &&
    || means OR
    && means AND



    How can this be usefull? Here's a e.g:
    Code:
    if(a == b && a == c) //means: if a is equal to b and also equal to c. if you use || in here it would be: if a is equal to b OR a is equal to c.
    {
    //CODE
    }
    *Here's one solution:

    Code:
    using System;
    
    namespace MpghTUTSolution1
    {
        class Program
        {
            static void Main()
            {
                Console.WriteLine("You will need to Insert 2 Numbers:");
                Console.WriteLine("First Number:");
                int aNum = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Secound Number:");
                int bNum = Convert.ToInt32(Console.ReadLine());
    
                if (aNum != bNum) //means they are different
                {
                    if ((aNum < 20 && aNum > 0) || (bNum < 20 && bNum > 0))
                    {
                        int result = 0;
    
                        if (aNum > bNum)
                        {
                            result = aNum - bNum;
                            Console.WriteLine("The biggest number is: " + aNum + " and the difference is " + result);
                        }
                        else
                        {
                            result = bNum - aNum;
                            Console.WriteLine("The biggest number is: " + bNum + " and the difference is " + result);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid Size Numbers, the Program will end");
                    }
                }
                else
                {
                    Console.WriteLine("Numbers are equal, the Program will end");
                }
    
                Console.ReadKey(); //to stop the program so you can see the text / result.
            }
        }
    }
    ---------*** Chapter: Cicles ***---------


    *Ok, let's say that you want to do something on your code that will need to repeat, and repeat and repeat until the user stops it, or until the user inserts what you want, or do what you want. There is a Solution!!! Cicles!

    We have a thing called:

    Do-While, which will DO <something> WHILE <something>

    Code:
    Do
    {
    //code
    }
    While(Condition)
    Here's a Simple E.g:

    Code:
    using System;
    
    namespace Cicles
    {
        class Program
        {
            static void Main()
            {
                Console.WriteLine("Welcome to the little Do-While Cicle try it Program.");
                Console.WriteLine("Insert a Fixed Number: (anything)");
                int fixedNum = Convert.ToInt32(Console.ReadLine());
                int biggerNum = 0;
    
                do //Will do the code inside {...} WHILE the biggerNum is lower then the Fixed one.
                {
                    Console.WriteLine("Insert a Bigger Number then the fixed one:");
                    biggerNum = Convert.ToInt32(Console.ReadLine());
                }
                while (biggerNum < fixedNum); //Isn't Do-While obvious? Do <Something> While <Something>
                //Lets say that I will: Do <Eat Something> While <I'm Hungry>.
                //The Condition should be Inside the ( ... );
    
                Console.WriteLine("Gratz! If you reached this is because you inserted a bigger number (or should)");
            }
        }
    }

    *There is another Cicle called: While


    Code:
    while(Condition)
    {
    //This will do basiclly the same as the one above, with a a small (or BIG..) difference:
    //The above one will Always start the cicle.. whenever what he did before without checking the condition Before, so basiclly, the Above one, does the Comparation at the END, and this one posted here, will do the comparation at the start of the while, which you will understand better at the future when you do lots of things by urself.
    }

    *And There is even another Cicle called: For.
    *This is probabily one of the most important things that you will learn or learned by now...


    *A Program that will type every number from 0 to 20:

    Code:
    using System;
    
    namespace ForAPP
    {
        class Program
        {
            static void Main()
            {
                int x;
                Console.WriteLine("-- Numbers from 0 to 20 --");
                Console.WriteLine("");
    
                for (x = 0; x <= 20; x = x + 1)
                {
                    Console.WriteLine("Number " + x);
                }
            }
        }
    }
    I know, you probably look at it and you get like: "Wth is this?". Im going to explain.

    For Works like this:



    I know it's quite wierd, and hard to understand, but i'm sure in a while you will get used to it, until then, use do-while, or while



    ****** STILL EDITING******

    *Sry for the sucky English*




    Reposting because the old one (2 weeks older), I am now unable to edit it and add things like i said i would, this is why im Reposting, and Also, i request Why06 if he can change the link of the one in the C++ Tut List.
    Thanks everyone.

    Last edited by 'Bruno; 01-16-2010 at 04:52 PM.
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  2. The Following 19 Users Say Thank You to 'Bruno For This Useful Post:

    An0nymousHelper (08-26-2010),Asasinull (01-03-2013),BlakkRaven (08-18-2011),coralboy22 (02-22-2010),danny1098222 (07-13-2011),GBot! (12-29-2010),Hassan (05-26-2010),Hell_Demon (01-17-2010),Invidus (10-09-2010),kkratos1 (02-01-2011),lolitek (07-05-2012),Lyoto Machida (02-12-2011),mega200 (12-14-2017),Playa3994 (07-07-2010),Void (01-15-2010),vudu3d (04-25-2012),wiiit1983 (10-20-2019),zesu08 (06-20-2010),[NoobZoned]1111 (10-16-2011)

  3. #2
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    I'm confused about the structure of a C# program, does it have to be a namespace?

    Can you make different classes? I only ask because the main function seems to be in a class. I don't quite understand how it works yet.


    Nice tutorial, I'm going to start C# once I understand a little more about assembly.

  4. The Following User Says Thank You to Void For This Useful Post:

    mega200 (12-14-2017)

  5. #3
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by Davidm44 View Post
    I'm confused about the structure of a C# program, does it have to be a namespace?

    Can you make different classes? I only ask because the main function seems to be in a class. I don't quite understand how it works yet.


    Nice tutorial, I'm going to start C# once I understand a little more about assembly.
    Well, Class program is where the program will ever Start, even if you use XNA (XNA is to C# what DX is to C++).

    here a Screen that may make you to understand somethings:



    Like you can see i do have another .Class which contains just a simple string.
    Also you can see that both have the same namescape, namespace is for the program to know what can he use in it, everything on the same namescape can be used in them. If i didn't have Cookies.cs (class) on the same namescape i couldnt use it on Class Program.cs which contains main and is where the program starts.

    Also in the solution explorer, as you may see, what's the name of the "project"... the namescape used in the whole program to let him know what is inside "his program"

    It's a bit hard for me to explain it for you even if i know it not sure why. But i hope that with that screen you understand a bit more of the C# Structure.
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  6. The Following 2 Users Say Thank You to 'Bruno For This Useful Post:

    coralboy22 (02-22-2010),Void (01-15-2010)

  7. #4
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Thank you, I very much understood what you're saying. But, is there any specific reason the main function is inside a class? What would happen if it wasn't in a class? Or is that impossible?

  8. #5
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by Davidm44 View Post
    Thank you, I very much understood what you're saying. But, is there any specific reason the main function is inside a class? What would happen if it wasn't in a class? Or is that impossible?
    that class, "Program" or w/e you want to call it, contains the data and methods (functions) definitions that the program uses to execute. And then she will basiclly look for "main()" to know what to do.

    I hope i help
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  9. #6
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Davidm44 View Post
    Thank you, I very much understood what you're saying. But, is there any specific reason the main function is inside a class? What would happen if it wasn't in a class? Or is that impossible?
    Everything is a class. It's like Java. Completely object oriented. A class can only be run if it has a main function in it I'm figuring. It may be a little confusing at first coming from strictly C++, but it's easy to get used too.

    EDIT: what Brinuz said.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  10. The Following 2 Users Say Thank You to why06 For This Useful Post:

    'Bruno (01-15-2010),Void (01-15-2010)

  11. #7
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    I guess it has its main function in a class because it runs on a VM?
    Ah we-a blaze the fyah, make it bun dem!

  12. #8
    falzarex's Avatar
    Join Date
    Apr 2008
    Gender
    male
    Location
    here
    Posts
    417
    Reputation
    14
    Thanks
    145
    uhh yeah coz its all .net anywayz
    and regarding namespaces like i mentioned before objects under same namespaces can interchange data between each other
    Quote Originally Posted by falzarex aka myself
    GTFO FUCKER U DONT BELONG IN THE INTERNETZ WORLD COZ ITS MINE


    This is an epic fail resume
    Hello VBfags.
    A 'member' of the almighty C++ section will soon join you, he is 13 year old, has the IQ and typing skills of a VBfag, so I thought he would fit in here nicely.

    A few reasons why he should be in this section instead of the C++ section:
    1) He has the IQ of a VBfag.
    2) He has no sense of grammer/spelling at all.
    3) He thinks he is pro(like most of the people in here)
    4) He thinks copy pasting is fun(exactly what you guys do)
    5) He loves it up the ass(he will keep you VBfags nice and warm)

  13. #9
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Yep Yep, C# is C++ and Java's illegitimate child. It is a LOT like java, but also has some stuff in common with C++. . . The one thing i prefer about C++ and Java is the way they do classes . . .

    It annoys me that a Class method definition becomes an inline function if defined in the class body. . .

Similar Threads

  1. [Tutorial]how to beggin with Vb for begginers
    By Rasta in forum Visual Basic Programming
    Replies: 2
    Last Post: 03-24-2011, 08:50 AM
  2. [TuT] C++ Beginners Tutorial RePost
    By Invidus in forum C++/C Programming
    Replies: 4
    Last Post: 03-12-2010, 10:08 PM
  3. [TUT] Basic Cheat Engine tutorial for begginers
    By rawr161 in forum Programming Tutorials
    Replies: 2
    Last Post: 08-14-2009, 06:41 AM
  4. Warrock Hack - Tutorial
    By Dave84311 in forum WarRock - International Hacks
    Replies: 667
    Last Post: 10-09-2007, 10:10 AM
  5. Photoshop Tutorials
    By Dave84311 in forum Art & Graphic Design
    Replies: 3
    Last Post: 12-31-2005, 07:21 AM