I”ve added a class by creating a code file named GradeBookTest.cs, when I try to run my application it is giving me this error: The namespace” already contains a definition for “GradeBookTest”.
You are watching: The namespace already contains a definition for
Here is my code – I am not sure how I can correct it?
pulic class GradeBookTest
//Main method begins program execution
public static void Main(string<> args)
// create a GradeBook object and assin it to myGradeBook
GradeBook myGradeBook = new GradeBook();
//call myGradeBook”s displayMessage method
} // end main
Saturday, September 29, 2012 6:10 PM
Sign in to vote
If you want to define the same class name at the same namespace, you need to define the partial key word at the beginning of the class name when defining it. It has been announced inside Partial Class Definitions (C# Programming Guide).
Hope it helps you.
orichisonic http://blog.csdn.net/orichisonic If a post answers your question, please click “Mark As Answer” on that post and “Mark as Helpful”.
Tuesday, October 2, 2012 7:54 AM
Sign in to vote
Open code in editor, go to top of code, press Control-F. In the dialog box that appears type GradeBook and look for where it occurs.
I”d guess that you will find two places where it is declared as a class. I think the one containing main is probably wrong – it usually defaults to Program.
BTW the title of the post does not say anything about what the problem is so anyone with a similar problem will probably fail to find it. Perhaps you could change it to some like “Namespace already contains definition” since that”s the error you are trying to fix.
Oops: does not have Main in class GradeBook but in GradeBookTest and that seems OK.
Regards David R ————————————————————— The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.Object-oriented programming offers a sustainable way to write spaghetti code. – Paul Graham.Every program eventually becomes rococo, and then rubble. – Alan Perlis The only valid measurement of code quality: WTFs/minute.