Results 1 to 10 of 10
  1. #1
    richdude212's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Tampa, FL
    Posts
    352
    Reputation
    10
    Thanks
    56
    My Mood
    Inspired

    [C#] Tutorial: Understanding Classes

    Start a console app project and add this code inside the namespace



    - Creating the class called Output
    Code:
    class Output
    - Declaring two strings the will hold our text
    Code:
            string myString;
            string nextString
    - Creating a method called Output and declaring two new strings that will hold the text that will be outputted.
    Code:
     public Output(string inputString, string input2String)
            {
                myString = inputString;
                nextString = input2String;
            }
    - Creating the method that will allow us to print (we will call this later)
    Code:
            public void print()
            {
                Console.WriteLine("{0} {1}", myString, nextString);
            }

    So far you should look like this:
    Code:
    class Output
        {
            string myString;
            string nextString;
    
            
            public Output(string inputString, string input2String)
            {
                myString = inputString;
                nextString = input2String;
            }
    
    
            public void print()
            {
                Console.WriteLine("{0} {1}", myString, nextString);
            }
    
    
        }

    Next add this:
    Code:
    class program
        {
    
            public static void Main() 
        {
            
            Output Out = new Output("First one", "Next one");
    
            
            Out.print(); 
            Console.Read();
        }
        }

    Code:
    Output Out = new Output("First one", "Next one");
    This snippet is declaring the class Output as a new name, out. It is setting it equal to Output with two strings.

    Code:
            Out.print(); 
            Console.Read();
    Now we call our print function which will display "First one Next one" on the screen. console.Read(); just holds it on the screen.

    Your finally code should look like this:
    Code:
    class Output
        {
            string myString;
            string nextString;
    
            // Constructor
            public Output(string inputString, string input2String)
            {
                myString = inputString;
                nextString = input2String;
            }
    
    
            public void print()
            {
                Console.WriteLine("{0} {1}", myString, nextString);
            }
    
    
        }
    
    
        class program
        {
    
            public static void Main() 
        {
            
            Output Out = new Output("First one", "Next one");
    
            
            Out.print(); 
            Console.Read();
        }
        }
    If I was of any help press thanks, if you have any questions please post them.
    [IMG]https://i516.photobucke*****m/albums/u330/richdude212-2.jpg[/IMG]


    [IMG]https://i516.photobucke*****m/albums/u330/richdude212/leet.gif[/IMG]

    Get NX Cash For Completing Offers Here! (will redirect)


    Remember to press when people help you!
    Not bad for $14.99 a month...

  2. The Following User Says Thank You to richdude212 For This Useful Post:

    giza123 (03-15-2011)

  3. #2
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,682
    My Mood
    Mellow
    Not very well explained really. No mention of what a constructor is or does (you just said make a method called Output..lol), sorta just copy and paste this and voila you have a class. More detail is needed because this is a fundamental in programming, it's necessary to explain it properly so people don't get the wrong impression at the very start of their programming career. My Java lecturer was explaining classes the other day and he did a good job (despite the fact that I nearly fell asleep with boredom) explaining all about instance variables, access modifiers, constructors, methods...etc. You need to actually go into some detail for this to count as a tutorial.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

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

    Hell_Demon (03-15-2011)

  5. #3
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,111
    Reputation
    1096
    Thanks
    1,971
    My Mood
    Doh
    Quote Originally Posted by Jason View Post
    Not very well explained really. No mention of what a constructor is or does (you just said make a method called Output..lol), sorta just copy and paste this and voila you have a class. More detail is needed because this is a fundamental in programming, it's necessary to explain it properly so people don't get the wrong impression at the very start of their programming career. My Java lecturer was explaining classes the other day and he did a good job (despite the fact that I nearly fell asleep with boredom) explaining all about instance variables, access modifiers, constructors, methods...etc. You need to actually go into some detail for this to count as a tutorial.
    TBH, i didn't read all your post, but I think it's pretty much easy to understand what he said.....Really really easy.

    ps:
    make it:
    Code:
    public static void Main(string[] args)
    {
          //BlaBla
    }
    Just a recomandation
    Last edited by ♪~ ᕕ(ᐛ)ᕗ; 03-15-2011 at 10:05 AM.

  6. #4
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,682
    My Mood
    Mellow
    Quote Originally Posted by Play&Win View Post


    TBH, i didn't read all your post, but I think it's pretty much easy to understand what he said.....Really really easy.

    ps:
    make it:
    Code:
    public static void Main(string[] args)
    {
          //BlaBla
    }
    Just a recomandation
    You even know what you're talking about? .

    If you actually bothered to read my post, I said classes were a <let me highlight the import parts for your selective reading>

    FUNDAMENTAL ASPECT of learning to program, i.e you LEARN THEM AT THE BEGINNING WHEN YOU DON'T KNOW AN INT FROM A STRING so special attention must be given to ENSURE THE NEW PROGRAMMER UNDERSTANDS WHAT A CONSTRUCTOR IS, WHAT A METHOD IS, WHAT ACCESS MODIFIERS DO, HOW TO CONSTRUCT A NEW INSTANCE OF THE CLASS AND CALL IT'S METHODS.

    Shit man, I didn't have any trouble understanding it either, but...oh wait... I already know how to program. Of course it's easy to understand if you know how to program, fuck sake.
    Last edited by Jason; 03-15-2011 at 11:17 AM.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  7. The Following User Says Thank You to Jason For This Useful Post:

    B1ackAnge1 (03-22-2011)

  8. #5
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,111
    Reputation
    1096
    Thanks
    1,971
    My Mood
    Doh
    Quote Originally Posted by Jason View Post


    You even know what you're talking about? .

    If you actually bothered to read my post, I said classes were a <let me highlight the import parts for your selective reading>

    FUNDAMENTAL ASPECT of learning to program, i.e you LEARN THEM AT THE BEGINNING WHEN YOU DON'T KNOW AN INT FROM A STRING so special attention must be given to ENSURE THE NEW PROGRAMMER UNDERSTANDS WHAT A CONSTRUCTOR IS, WHAT A METHOD IS, WHAT ACCESS MODIFIERS DO, HOW TO CONSTRUCT A NEW INSTANCE OF THE CLASS AND CALL IT'S METHODS.

    Shit man, I didn't have any trouble understanding it either, but...oh wait... I already know how to program. Of course it's easy to understand if you know how to program, fuck sake.
    damn sorry if I made you mad. but I didn't say that you can't program..Ar nvm.Sorry again...

  9. #6
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,682
    My Mood
    Mellow
    Quote Originally Posted by Play&Win View Post


    damn sorry if I made you mad. but I didn't say that you can't program..Ar nvm.Sorry again...
    I never said you did say that, I said it IS easy to understand...if you already know how to program. To beginners that actually need the tutorial, they won't get some of the concepts.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  10. #7
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,111
    Reputation
    1096
    Thanks
    1,971
    My Mood
    Doh
    Quote Originally Posted by Jason View Post


    I never said you did say that, I said it IS easy to understand...if you already know how to program. To beginners that actually need the tutorial, they won't get some of the concepts.
    well now I understood. Well, yes you're right, he should explain what he said...Thanks, but the method that you said your previous post was like: WAW! .

  11. #8
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,682
    My Mood
    Mellow
    Quote Originally Posted by Play&Win View Post


    well now I understood. Well, yes you're right, he should explain what he said...Thanks, but the method that you said your previous post was like: WAW! .
    [highlight=c#]
    public Output(string inputString, string input2String)
    {
    myString = inputString;
    nextString = input2String;
    }
    [/highlight]

    How is a person with little prior programming experience going to know that this is a constructor?

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  12. #9
    GrimDesire's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    New York, Crazy Life
    Posts
    21
    Reputation
    10
    Thanks
    2
    My Mood
    Confused
    O_O im still learning c++ sooo this needs to be explained a little more

    [YOUTUBE]<iframe title="YouTube video player" width="195" height="140" src="https://www.youtube.com/embed/j5-yKhDd64s" frameborder="0" allowfullscreen></iframe>[/YOUTUBE]

  13. #10
    MC²'s Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    somewhere between here and there
    Posts
    2,794
    Reputation
    174
    Thanks
    314
    My Mood
    Brooding
    thanks kinda helped