Corrected enum code declaration. (#32854)
* Corrected enum code. Cannot declare: public enum phylum; Since this code will produce an error. If someone will copy the same code, it will not compile and run. I updated the code so that when someone will copy the code, it will not produce an error. * I also updated the spacing and tabbing on code. * Corrected the constructor DefineAnimal to Animal since the name of the class is Animal and DefineAnimal will produce an error. * Remove enum on parameter of constructor since this will produce an error. * Corrected class Dog as public enum breed will produce an error.
This commit is contained in:
committed by
Randell Dawson
parent
62ba46f9ce
commit
49c2c7164a
@ -29,35 +29,38 @@ In C# the `:` symbol is used to denote inheritance. This is called when creating
|
||||
# Base class
|
||||
```
|
||||
public class Animal
|
||||
{
|
||||
public int ID;
|
||||
public string title;
|
||||
public enum phylum;
|
||||
public enum dietType;
|
||||
|
||||
public DefineAnimal(int id, string name, enum phy, enum diet)
|
||||
{
|
||||
this.ID = id;
|
||||
this.title = name;
|
||||
this.phylum = phy;
|
||||
this.dietType = diet;
|
||||
public int ID;
|
||||
public string title;
|
||||
public enum phylum { };
|
||||
public enum dietType { };
|
||||
|
||||
public phylum _phylum;
|
||||
public dietType _dietType;
|
||||
|
||||
public Animal(int id, string name, phylum phylum, dietType diet)
|
||||
{
|
||||
this.ID = ID;
|
||||
this.title = name;
|
||||
this._phylum = phylum;
|
||||
this._dietType = diet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
# Derived class
|
||||
```
|
||||
public class Dog : Animal
|
||||
{
|
||||
public enum breed;
|
||||
public int levelOfTraining;
|
||||
|
||||
public void SayWoof()
|
||||
{
|
||||
Console.WriteLine("Woof");
|
||||
}
|
||||
}
|
||||
{
|
||||
public enum breed { };
|
||||
public int levelOfTraining;
|
||||
|
||||
public void SayWoof()
|
||||
{
|
||||
Console.WriteLine("Woof");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<!--- To do - Constructor rules, Abstract, Sealing derived classes--->
|
||||
|
Reference in New Issue
Block a user