|
||
|
|
#1 (permalink) |
|
Forum Novice
|
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!~
|
|
|
|
|
|
#2 (permalink) | |
|
ConnectUO Creator
Join Date: Jan 2004
Age: 27
Posts: 4,818
|
Quote:
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()
{
}
}
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;
}
}
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 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()
{
}
}
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);
}
}
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 |
|
|
|
|
|
|
#4 (permalink) | |
|
ConnectUO Creator
Join Date: Jan 2004
Age: 27
Posts: 4,818
|
Quote:
![]()
__________________
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 |
|
|
|
|
|
|
#5 (permalink) | ||
|
Forum Expert
|
Quote:
Code:
Math101 mathClass = new Math101(); int result = mathClass.Math.Add(2, 2); Pardon my poor terminology; and definitely feel free to correct me on any and all aspects of the above. I too am learning. ![]()
__________________
Quote:
|
||
|
|
|
|
|
#6 (permalink) | |
|
RunUO Forum Moderator
|
Quote:
__________________
I always try to help
![]() Sometimes, I don't know how.... ![]() My Web Page Forum Rules ------------------------------------------------------------- Extensive OWLTR System | Token System | World Teleporters ------------------------------------------------------------- |
|
|
|
|
|
|
#8 (permalink) |
|
ConnectUO Creator
Join Date: Jan 2004
Age: 27
Posts: 4,818
|
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 |
|
|
|
|
|
#9 (permalink) | ||
|
Forum Expert
|
Quote:
Yeah, just noticed that Add and Math are in-fact both functions.![]()
__________________
Quote:
|
||
|
|
|
|
|
#10 (permalink) |
|
ConnectUO Creator
Join Date: Jan 2004
Age: 27
Posts: 4,818
|
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 |
|
|
|
|
|
#12 (permalink) |
|
ConnectUO Creator
Join Date: Jan 2004
Age: 27
Posts: 4,818
|
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|