locked
Class Inheritance error!.." RRS feed

  • Question

  • User1421620300 posted

    Can someone help me to resolve this error! I have about 4 other classes in my project. But this is the only class with an error! Markus.

    Severity Code Description Project File Line Suppression State
    Error CS0101 The namespace 'OOP_Coupling.com.composition' already contains a definition for 'Dep' OOP_Coupling V:\C# Projects\OOP_Coupling\OOP_Coupling\com\composition\CompDepartment.cs 10 Active

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;


    namespace OOP_Coupling.com.composition
    {
    enum Dep                 //bold code is error!!!
    {
    comp,
    art,
    biz
    }
    class CompDepartment : Department
    {
    //public string Name { get; set; }
    //public string CompDirector { get; set; }
    public int NumberOfComputerLabs { get; set; }

    public List<Department> departments { get; set; } = new List<Department>();

    public void AddDepartment(string name, string director, Dep dep, int num)
    {
    if (dep == Dep.art)
    {
    ArtDepartment art = new ArtDepartment();
    art.Name = name;
    art.Director = director;
    art.NumberOfStudents = num;

    departments.Add(art);
    }

    else if (dep == Dep.comp)
    {
    CompDepartment com = new CompDepartment();
    com.Name = name;
    com.Director = director;
    com.NumberOfComputerLabs = num;

    departments.Add(com);
    }

    }
    }
    }

    Monday, November 25, 2019 12:25 AM

Answers

  • User288213138 posted

    Hi Markus33,

    The namespace 'OOP_Coupling.com.composition' already contains a definition for 'Dep' OOP_Coupling

    According to your code, I can't reproduce your problem.

    But as far as I know, The namespace x already contains a definition for x error is usually caused by the other namespace contained a enum with the same name. So please check if your code contains the same name "Dep".

    If you still can't solve your question, please post your complete code.

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 25, 2019 9:12 AM
  • User753101303 posted

    Hi,

    It seems you declared already something named Dep (maybe a class ?) in the same namespace. Change the enum name or use the "Object Browser" to see if this is not declared alrady in some other file.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 25, 2019 10:04 AM

All replies

  • User288213138 posted

    Hi Markus33,

    The namespace 'OOP_Coupling.com.composition' already contains a definition for 'Dep' OOP_Coupling

    According to your code, I can't reproduce your problem.

    But as far as I know, The namespace x already contains a definition for x error is usually caused by the other namespace contained a enum with the same name. So please check if your code contains the same name "Dep".

    If you still can't solve your question, please post your complete code.

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 25, 2019 9:12 AM
  • User753101303 posted

    Hi,

    It seems you declared already something named Dep (maybe a class ?) in the same namespace. Change the enum name or use the "Object Browser" to see if this is not declared alrady in some other file.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 25, 2019 10:04 AM