does not contain a constructor ... error

jdy0803

Member
Joined
May 20, 2013
Messages
17
Programming Experience
10+
The following code is from Microsoft MSDN.


C#:
public class Employee4
    {
        public string id;
        public string name;
        public Employee4() 
        {


        }
        public Employee4(string name, string id)
        {
            this.name = name;
            this.id = id;
        }
        public static int employeeCounter;
        public static int AddEmployee()
        {
            return ++employeeCounter;
        }
    }
    class MainClass : Employee4 //compile error here!!!
    {
        static void Main(string[] args)
        {
        }
    }
If compile this, following error occurs at class MainClass : Employee4.


'StaticClass.Employee4' does not contain a constructor that takes 0 arguments


Can anybody find any wrong in the code?
 
Despite the fact that it's rather horrible code, that compiles fine for me. Here's what I did:

1. Create a new Console Application project.
2. Add the highlighted parts to the code of the main class:
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program [B][COLOR="#FF0000"]: Employee4[/COLOR][/B]
    {
        static void Main(string[] args)
        {
        }
    }

    [B][COLOR="#FF0000"]public class Employee4
    {
        public string id;
        public string name;
        public Employee4()
        {


        }
        public Employee4(string name, string id)
        {
            this.name = name;
            this.id = id;
        }
        public static int employeeCounter;
        public static int AddEmployee()
        {
            return ++employeeCounter;
        }
    }[/COLOR][/B]
}
3. Built the project.
 
Back
Top Bottom