Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Must declare a body becase it is not marked abstract, extern or partial

I have created the following class. However, I cannot get past the error:

Must declare a body becase it is not marked abstract, extern or partial

The classe is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.CompilerServices;

namespace VDSORDAL
{
        public abstract class ObjectComparer<T> : IComparer<T>
        {
            public ObjectComparer(string compareField, string direction);

            private string compareField; 

            public string CompareField 
            { 
                get { return compareField; } 
                set { compareField = value; } 
            }

            public string Direction
            { 
                get { return compareField; } 
                set { compareField = value;} 
            }

            public abstract int Compare(T x, T y);
        }
}

Can someone point out the error in my ways and also give me a brief explanation as to what I am doing wrong and why it is throwing this error?

like image 908
Ricardo Deano Avatar asked Jul 28 '10 16:07

Ricardo Deano


1 Answers

You have declared the constructor without a body:

public ObjectComparer(string compareField, string direction);

If you don't want the constructor to do anything, you can still put an empty body ({ }) there.

As a side note, it doesn't make sense to have an abstract class with a public constructor -- the constructor should be protected, because the constructor can only be "called" by classes deriving from it anyway.

like image 76
Mark Rushakoff Avatar answered Oct 23 '22 21:10

Mark Rushakoff