## 3 replies

Last post Mar 14, 2012 12:38 PM by mameenkhn

Member

5 Points

14 Posts

### Adding Variable result integer

Mar 14, 2012 12:18 PM|uahmed|LINK

Hi

When i run below code it gives me integer value

```var st1 ="asd";
var st2 = st1[0]+st1[1];
<h1>st2</h1>```

and i am expecting "as" only . Can anyone tell me where i am wrong

Member

532 Points

255 Posts

### Re: Adding Variable result integer

Mar 14, 2012 12:26 PM|dinesh kumar nayak|LINK

It should not give.

But still if this is the case then you can write

`var st2 = st1[0].ToString()+st1[1].ToString();`
Thanks & Regards
Jai Jagannath

Contributor

4946 Points

873 Posts

### Re: Adding Variable result integer

Mar 14, 2012 12:29 PM|GmGregori|LINK

The correct syntax is

```@{
var st1 ="asd";
var st2 = st1.Substring(0,2);
}
<h1>@st2</h1>```

Participant

1283 Points

379 Posts

### Re: Adding Variable result integer

Mar 14, 2012 12:38 PM|mameenkhn|LINK

Dear uahmed..

This is because of the + operator..

var st2 = st1[0]+st1[1];

because if you use + then C# will assume both the operands as Integer and take the ascii value of the alphabets

st2 = 97 + 115;

97 is ascii of a

and 115 is for s

Please if my post helped you
--------------------------------------------------