Hi I'm creating a code for my class and what I'm trying to do is to create a triangle class that is derived from abstract class TwoDimShape. However; when I create the triangle class and use base as a variable I get an error. My teacher wants us to use the variable "base" here is my code and the error, any help is appreciated.
public class Triangle : TwoDimShape
private double base;
private double height;
and the error is: Error 1 Invalid token 'base' in class, struct, or interface member declaration
Your teacher is asking the impossible.
As base is a reserved word, you cannot use it as a variable.
However, you could use: @base Now C# ignores it's a reserved word. basis which is an alternative for base. _base a correctly used variable name with a resemblance to the word base.
C# is case-sensitive. Are you sure your teacher didn't specify you to use "Base"? You can use "Base"--capital "B". Although, I wouldn't recommend using a different case of a reserved word. It would be similiar to you doing the following: