Re: DESPARATE HELP NEEDED WITH C#

Tech-Archive recommends: Fix windows errors by optimizing your registry



On 21 Jan 2007 16:40:58 -0800, "Chrissy" <cewerdt@xxxxxxxxx> wrote:

I took a C# class as an elective and received an incomplete in it and
am desparate for help. I have two assignments left (arrays and
inheritance) and would gladly pay anyone that can assist me with
this.

I want you to know that I'm a 41 year old mother of three boys (ages
9, 7, and 2) and have done my very best to muddle through this
course. Sadly, my old brain is not equipped to handle it. LOL

Chrissy

Inheritance: assume that you want to develop a graphics software.

Before you write some code (being it in C# or C++ or other language),
you should have an idea of the objects ("classes") that will be part
of your software system.

For a graphics software, the idea of "Shape" object pops up in mind.
So, you could define a class called Shape, to represents a geometrical
shape.

The shape would have some "attributes" (or "properties", in C#
terminology), like its background colour, or the colour of its
contour, its position in space, etc.

The shape would also have some "operations" (or "instance methods" in
C# terminology) like drawing itself, or translate, or rotate.

So, we end up with defining a class something like this:

+-----------------+
| Shape | <-- Class name
+-----------------+
| Position | <-- Attributes (Properties)
| BackgroundColor |
| ContourColor |
+-----------------+
| Draw | <-- Methods
| Translate |
| Rotate |
+-----------------+

Then, you will have different kinds of objects, like a triangle, a
circle, a square, an ellipse, a regular poloygon, etc.
You would define a class for each of them (so you will end up having
classes: Circle, Square, RegularPolygon, etc.)

All these classes will *inherit* from the shape class, because all
these classes ARE shapes. This means that all these classes will have
Position, BackgroundColor, etc. properties, and all will have Draw,
Translate, Rotate methods.

However, each one of these classes will have a different
implementation for e.g. the Draw method: the Circle class
implementation of the Draw() method will draw a circle; the
Square.Draw() method will draw a square, etc.

Moreover, each of this classes could add *more* information than the
information present in the *base* class (i.e. the Shape class).

e.g. a Circle class could have a Radius property (having a radius is a
concept typical of circles, but not of squares or polygons).

So:

- You have a *base* class (Shape), which has some properties and
methods

- You have some *derived* classes (Circle, Square, ...). They are
derived from the base class, or they *inherit* from the base class.
This means that the derived classes have all the properties and
methods of the base class, plus the derived classes may add some more
methods and properties (like Circle class, it has the Radius property
that the Shape class has not).

Note that inheritance in C# is available for *classes* (not for
*structures*).

Moreover, you should know the existance of two fundamental keywords
for inheritance mechanics: the "virtual" keyword and the "override"
keyword.

In the above example, the Shape methods like Draw, Translate, etc.
will be defined as *virtual*. It means that derived classes could
override them. In derived classes implementation you will use the
"override" keyword, to tell the compiler that you are providing the
customized implementation of that method.

Another example is the object hierarchy in C#.

C# objects are derived from the "root" System.Object class.
System.Object has a method called ToString(), which purpose is to give
a string representation of the object content. Obviously, each derived
class will provide its custom implementation of ToString() method.

In the System.Object the ToString() method would be defined as:

public virtual string ToString()

This means that everyone can access the method (public) and that the
method can be overridden in derived classes (virtual).

When you define a custom class, this class is derived from
System.Object, so this class could redefine the ToString() method.
And you will have:

// In your class, e.g. in a Circle class:

public override string ToString()
{
return String.Format(
"I'm a circle with radius = {0}", radius );
}

As other have suggested, you could search more information on Google
and C# tutorials (I'm sure that there will be a lot of!).

As for your age, I think it is not absolutely a problem :)

I'm sure that there are some outstanding people also older than you
(some of my programming "heros" :) - I think they work in Microsoft -
like Don Box or other "progamming rock-stars" like the software
engineers behind Windows NT kernel operating system like Dave Weise,
all these outstanding people I think are older than you - or are as
old as you - and produce great software).

And Enrico Fermi was 54 when he wrote a great physics article about
non-linear systems.

etc.

Best
MrAsm
.



Relevant Pages

  • Re: Not pure virtual functions and mixing virtual and non virtual methods
    ... Should I call base class implementation or not? ... But doing the above assumes that one answer is good for all, that all derived classes will want the base class method called in the same way. ... More generally, the way I see it, if you combine invariant implementation with variant parts, you have no elegant way to change the variant part. ... Following them will remove all inheritance relationships. ...
    (comp.object)
  • ViewState property can not be accessed in derived class ???
    ... Using inheritance, doesn't 'protected' mean that derived classes can ... access that data if specified as protected in the base class? ... ViewState property can not be accessed ??? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How can access varible from different class/
    ... I believe the problem here is about inheritance. ... Both derived classes were inheriting form the base class ... I have textBoxe1 in 2 derived classes of the same project, how can I differentiate between them? ... Each of your forms are objects that were instantiated at some point, which means that both forms have properties and methods which derive from the System base form. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: How can access varible from different class/
    ... I believe the problem here is about inheritance. ... Both derived classes were inheriting form the base class ... If I have textBoxe1 in 2 derived classes of the same project, how can I differentiate between them? ... System.Windows.Forms.Form does not contain a textBox1, so I don't see where the problem with inheritance is coming into play. ...
    (microsoft.public.dotnet.framework.windowsforms)