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.

sing System;

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:

string employee = "John";
string Employee = "Bill";
string eMployee = "Joe";
string emPloyee = "Jane";

All would be permitted, but will likely lead to confusion either for you or for someone who has to maintain your code.

Perhaps part of the lesson to be learned from your assignment is about the case-sensitivity of C#.

Thanks guys, I changed the variable to basee, instead of base. Thanks again

Perhaps part of the lesson to be learned from your assignment is about the case-sensitivity of C#.

I sure hope not, because that'd be a cruel and stupid way of teaching a simple rule of the language.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.