Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 10-18-2007, 10:48 PM   #1 (permalink)
Forum Novice
 
AntKneeM's Avatar
 
Join Date: Sep 2007
Location: Lost somewhere in the trees......
Age: 17
Posts: 217
Send a message via AIM to AntKneeM
Default Looking for Good Tut

Iam not sure if this is allowed or not, but ive searched and ive yet to come accross and C# Tutorial to keep my attention long enough to explain to me what a class is ( Example ) iam looking for a decent C# Tutorial that is extensive BUT breaks things down and explains things to me and can help me understand better the C# language ?? so if anyone knows of a good one for beginners please let me know!~
__________________
If someone asks for help its your job to help them.......words of a wise man!

Quote:
Originally Posted by TMSTKSBK View Post
Stabbing your monitor in the face is the solution for a lot of problems.
AntKneeM is offline   Reply With Quote
Old 10-19-2007, 02:30 AM   #2 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 27
Posts: 4,818
Default

Quote:
Originally Posted by AntKneeM View Post
Iam not sure if this is allowed or not, but ive searched and ive yet to come accross and C# Tutorial to keep my attention long enough to explain to me what a class is ( Example ) iam looking for a decent C# Tutorial that is extensive BUT breaks things down and explains things to me and can help me understand better the C# language ?? so if anyone knows of a good one for beginners please let me know!~
Goto your local book store, or online such as amazon and buy the bool "Learning C#" by O'Reilly Publishing. This book is my #1 recommendation to people looking to really learn C# but can't quite grasp the C# tutorials on the web (same problem I had ). Anyway this book is awsome cause it descibes things with metaphors(which I love).

But to answer your question, "What is a class". The simply answer would be to descibe it like school. You goto school and you have 'classes' each 'class' contains information reguarding a subject. Generally, when you goto school you start with the basics and move on up the ladder to more advanced things, but they are all relative to the base class. In programming you have the same principals. You start making objects with a base class and move on up with new classes with the same base class. Lets look at an example.

Lets take my metaphor and pretend we are writing code for Math 101.

So what do we know about Math 101. We know that it is going to be able Math, and we know we will learn some basic math functions. So we would start out with

Code:
public class Math101
{
    public Math()
    {

    }
}
Now, in Math 101 we learn things like Add, Subtract, Multiply and Divide. So our base Math class needs to have these functions(also called methods).

Code:
public class Math101
{
    public Math()
    {

    }

    public int Add(int a, int b)
    {
        return a + b;
    }


    public int Subtract(int a, int b)
    {
        return a - b;
    }


    public int Multiply(int a, int b)
    {
        return a * b;
    }


    public int Divide(int a, int b)
    {
        return a / b;
    }
}
So there, now we have our basic math class we have called Math101

If we wanted to use our Math101 class in some code we could now do so like this

Code:
Math101 mathClass = new Math101();
int result = Math.Add(2, 2);
In this example result would be 4 since our add function returns the result of 2 + 2. Now, like I was saying earlier, in school we have a base class and we move up to more advanced classes. However something to keep in mind is that the base functions always stay with us as we progress through the more advanced classes

In programming we call this 'Inheritance'. Basically this means our new class will contain the same functions and functionality of its base class, just as Math 102 would contain the same math functions in Math 101.

So for example
Code:
public class Math102 : Math101
{
    public Math102() : base()
    {

    }
}
Now since this is a more advanced class it needs new, more advanced functions. So lets assume in Math 102 we learn how to average numbers. We would need to Add all the number supplied to our function together then divide them by the count of numbers passed to be averaged. Well since we already learned how to Add and Divide in our Math 101 class, we can use these same functions to help us with our work.

Lets take a look:
Code:
public class Math102 : Math101
{
    public Math102() : base()
    {

    }

    public int Average(int[] values)
    {
        int added = 0;
        for(int i = 0; i < values.Length; i++)
        {
            added = Add(added, values[i]);
        }

        return Divide(added, values.Length);
    }
}
See how I am able to use the functions from the base class(Math 101). This is basically how classes work, and how they should be used.

If you have questions regarding this please feel free to ask.
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 10-19-2007, 08:32 AM   #3 (permalink)
Forum Novice
 
AntKneeM's Avatar
 
Join Date: Sep 2007
Location: Lost somewhere in the trees......
Age: 17
Posts: 217
Send a message via AIM to AntKneeM
Default

Thx Jeff, Appreciate it... ill deff check that out that is what i was looking for for something to break things down for me, and that was and example i know what a class is but thx
__________________
If someone asks for help its your job to help them.......words of a wise man!

Quote:
Originally Posted by TMSTKSBK View Post
Stabbing your monitor in the face is the solution for a lot of problems.
AntKneeM is offline   Reply With Quote
Old 10-19-2007, 10:56 AM   #4 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 27
Posts: 4,818
Default

Quote:
Originally Posted by AntKneeM View Post
Thx Jeff, Appreciate it... ill deff check that out that is what i was looking for for something to break things down for me, and that was and example i know what a class is but thx
np you can always ask questions here to
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 10-19-2007, 02:59 PM   #5 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,149
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

Quote:
Originally Posted by Jeff View Post
Code:
Math101 mathClass = new Math101();
int result = Math.Add(2, 2);
I could be wrong, but my thinking was that this should read:
Code:
Math101 mathClass = new Math101();
int result = mathClass.Math.Add(2, 2);
I was just thinking that mathClass would have to be called before you could call Math() because that function belongs to Math101, which is being referenced as mathClass.

Pardon my poor terminology; and definitely feel free to correct me on any and all aspects of the above. I too am learning.
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 10-19-2007, 05:03 PM   #6 (permalink)
RunUO Forum Moderator
 
daat99's Avatar
 
Join Date: Dec 2004
Location: Israel
Age: 27
Posts: 8,163
Send a message via ICQ to daat99 Send a message via AIM to daat99
Default

Quote:
Originally Posted by Storm33229 View Post
I could be wrong, but my thinking was that this should read:
Code:
Math101 mathClass = new Math101();
int result = mathClass.Math.Add(2, 2);
I was just thinking that mathClass would have to be called before you could call Math() because that function belongs to Math101, which is being referenced as mathClass.

Pardon my poor terminology; and definitely feel free to correct me on any and all aspects of the above. I too am learning.
You are correct in your remarks but to Jeff's defense, he was just posting pseudo code for an example and not a real working code.
__________________
I always try to help
Sometimes, I don't know how....

My Web Page
Forum Rules
-------------------------------------------------------------
Extensive OWLTR System | Token System | World Teleporters
-------------------------------------------------------------
daat99 is offline   Reply With Quote
Old 10-19-2007, 06:02 PM   #7 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,149
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

Quote:
Originally Posted by daat99 View Post
You are correct in your remarks but to Jeff's defense, he was just posting pseudo code for an example and not a real working code.
Oh, wasn't quite aware of that. ^_^ sorry.
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 10-19-2007, 09:00 PM   #8 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 27
Posts: 4,818
Default

Quote:
Originally Posted by Storm33229 View Post
Oh, wasn't quite aware of that. ^_^ sorry.
not to mention it would be

Code:
Math102 math102Class = new Math102();
int result = math102Class.Add(2, 2);
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 10-19-2007, 09:48 PM   #9 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,149
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

Quote:
Originally Posted by Jeff View Post
not to mention it would be

Code:
Math102 math102Class = new Math102();
int result = math102Class.Add(2, 2);
Yeah, just noticed that Add and Math are in-fact both functions.
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 10-20-2007, 01:23 AM   #10 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 27
Posts: 4,818
Default

Quote:
Originally Posted by Storm33229 View Post
Yeah, just noticed that Add and Math are in-fact both functions.
Math isnt a function its a constructor, its what you call to create the object.
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 10-20-2007, 10:51 AM   #11 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,149
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

I thought anything with () after it was a function? =/
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 10-20-2007, 01:39 PM   #12 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 27
Posts: 4,818
Default

Quote:
Originally Posted by Storm33229 View Post
I thought anything with () after it was a function? =/
Technically i spose it is, but it's return type is its self. Thus its called a constructor, as in how you construct the object.
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 10-20-2007, 06:48 PM   #13 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,149
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

Quote:
Originally Posted by Jeff View Post
Technically i spose it is, but it's return type is its self. Thus its called a constructor, as in how you construct the object.
Ah, understood and noted.
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5