tags:

views:

213

answers:

3
+4  Q: 

Using minus in 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);  
+12  A: 

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 :-)

lasseespeholt
ok it solved.thanks.i copied that code and the problem was this
arash
Well, the 'minus' on the keyboard is sort of a hyphen/minus crossover. There is a specialized minus character defined in unicode. However, he's trying to use an *en dash*.
Thorarin
@Thorarin I have clarified it now.
lasseespeholt
A: 

That character... whatever character it is... is not a minus (ascii code 45).

Will
It is a mathematical minus sign, but not the one on our ASCII keyboards (ASCII code 45 as you say).
BoltClock
@Bolt yar. Seems he copypasted some code from a blog. Never a pleasant experience.
Will
+2  A: 

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:

BoltClock