Hi All,
I'm years out of practice and started to re-learn programming. I thought a fun way to learn inheritance is have the user choose a species and a list of sub-species will appear and so on and so forth.
I had my base and derived class in the same file as my opening form but then it complained I can only have 1 partial class in a file so I split it into a second .cs file. Now I getwhen I try to run the program.Error The namespace '<global namespace>' already contains a definition for 'kelf'
I ran the search and it only found 4 instances of kelf (all listed in the same new Fox.cs file).
Fox.cs
form1.csCode:public abstract class kelf { private string name; private string species; private int gestPeriod; public kelf(string species) { this.species = species; } ~kelf() { } public string GetSpecies() { return this.species; } } public class kelf : Foxes { /*public Fox() { } public void test() { messagebox(this.species); }*/ }
In the solution Explorer my Fox.cs is a direct sub-node of the solution if that makes any difference.Code:using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Inheritance { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if(cmbAnimals.Text == "") { MessageBox.Show("You must choose a top level species"); } else { //Animal tiger = new Animal(lblAnimal.Text); } } private void cmbAnimals_SelectedIndexChanged(object sender, EventArgs e) { switch(cmbAnimals.Text.ToUpper()) { case "CANIDAE": lblAnimal.Text = "FOX chosen"; //Fox newFox = new Fox(); break; case "GIRAFFA CAMELOPARDALIS": lblAnimal.Text = "Giraffa camelopardalis"; break; case "PANTHERA TIGRIS": lblAnimal.Text = "Panthera tigris"; break; default: break; } } } }
So it goes
Solution
-Properties
-References
-Form1.cs
--Form1.Designer.cs
--Form1.resx
-Fox.cs
-Program.cs
I tried looking up this error and it says my project has this class name somewhere else but I ran the search and it only found the 4 cases there. I checked syntax for Inheritance and it seemed correct to me. I'm not sure what I did wrong so any suggestions would be great/




Reply With Quote