Geeks With Blogs
Saqib Ullah BootStrapper Know How

My following class is a complete C# class because its contain all possible declarations.

using System;

class MyClass
{
    public const int MyConst = 45;
    public int MyField = 64;
    public static int MyStaticField = 65;
    public void MyMethod()
    {
      
Console.WriteLine("MyClass.MyMethod call");
    }

    public int MyProperty
    {
        get
        {
            return MyField;
        }

        set
        {
          
MyField = value;
        }
    }

    public event EventHandler MyEvent;

    public int this[int index]
    {
        get
        {
            return 0;
        }

        set
        {
            Console.WriteLine("this[{0}] = {1}", index, value);
        }
    }

    public static MyClass operator +(MyClass a, MyClass b)
    {
        return new MyClass(a.MyField * b.MyField);
    }

    public MyClass()
    {
        Console.WriteLine("Instance constructor call");
    }

    public MyClass(int value)
    {
        MyField = value;
        Console.WriteLine("Instance constructor call");
    }

    ~MyClass()
    {
        Console.WriteLine("Finalizer call");
    }

    static MyClass()
    {
        MyStaticField *= 2;
        Console.WriteLine("Static constructor call");
    }

    internal class MyNestedClass
    { }

}

Class members can include constants, fields, methods, properties, events, indexers, operators, instance constructors, finalizers, static constructors, and nested type declarations.

Yours Suggestions
{
     if any thing I left in the above so please corrects me thank.
 }

Posted on Friday, June 8, 2007 9:02 PM OOPs , .Net | Back to top


Comments on this post: what is C# complete class?

# re: what is C# complete class?
Requesting Gravatar...
I'm not at all sure what you mean by a "complete class" but you might consider:

- override ToString(), GetHashCode() and Equals(...)
- override the equality and inequality operators
- implement IComparable

as I say, I don't know what a "complete" class is, but I would expect to see the above on a "first class" class.
Left by Alan Dean on Jun 09, 2007 12:41 AM

Your comment:
 (will show your gravatar)


Copyright © Saqib Ullah | Powered by: GeeksWithBlogs.net