Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using minus in C#

Tags:

c#

I want to use - in the code below but Visual Studio doesn't let me to use it and gives "error, unexpected character".

    Name = objFileInfo.Name.Substring(0,  
        objFileInfo.Name.Length – objFileInfo.Extension.Length);  
like image 646
Arash Avatar asked Aug 19 '10 14:08

Arash


2 Answers

It is not a minus you are using:

Yours (char 8211, a math minus):

Minus (shorter, char 45 ascii, a dash which represents minus in C#):

-

Try copy the c# minus I use above and it will work :-)

like image 181
Lasse Espeholt Avatar answered Oct 03 '22 07:10

Lasse Espeholt


In C# (and I imagine almost any other programming language), the minus sign is simply represented by an ASCII dash, or hyphen-minus, which is a single keystroke on standard ASCII keyboards:

-

Not the mathematical minus symbol, which you're using:

like image 40
BoltClock Avatar answered Oct 03 '22 07:10

BoltClock