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;
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
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
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.
Member
251 Points
423 Posts
Class Inheritance error!.."
Nov 25, 2019 12:25 AM|Markus33|LINK
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);
}
}
}
}
Contributor
3370 Points
1409 Posts
Re: Class Inheritance error!.."
Nov 25, 2019 09:12 AM|samwu|LINK
Hi Markus33,
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
All-Star
48500 Points
18071 Posts
Re: Class Inheritance error!.."
Nov 25, 2019 10:04 AM|PatriceSc|LINK
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.