0

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

4
Contributors
4
Replies
25
Views
2 Years
Discussion Span
Last Post by deceptikon
1

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.

Edited by ddanbe: typos

2

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#.

Edited by cgeier

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.