Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What meaning about the C# code

0 views
Skip to first unread message

yxq

unread,
Nov 18, 2009, 7:02:59 PM11/18/09
to
((char)('A' + i)).ToString();

i is As Integer, what meaning about the code above? how to convert to VB.NET
code? Thank you.

I have converted to the VB.NET code, but it is not right.
CChar(("A"c + i)).ToString()


Armin Zingler

unread,
Nov 18, 2009, 7:25:57 PM11/18/09
to
yxq schrieb:

I do not know C# well but the code obviously creates letter i in the alphabet.
This I am just able to manage without being a C# expert. ;)

My version was: (types used for less overhead)

Dim CodeA = Convert.ToUInt16("A"c)
Dim offset As UShort = 17
Dim NewCode = Convert.ToChar(CodeA + offset)

Or just replace CodeA by the literal 65US (unsigned short suffix) that we programmers
know by heart anyway. :) Oh, and add NewCode.ToString() if really required.


--
Armin

Andrew Morton

unread,
Nov 19, 2009, 6:21:25 AM11/19/09
to
yxq wrote:
> ((char)('A' + i)).ToString();
>
> i is As Integer, what meaning about the code above? how to convert to
> VB.NET code? Thank you.

Or the other way of looking at it compared to Armin's answer: if the desired
result is "A1", "A2"... where i=1, 2... then

"A" & i.ToString()

--
Andrew


Family Tree Mike

unread,
Nov 19, 2009, 7:42:01 AM11/19/09
to

"Andrew Morton" wrote:

> .
>

But that is not what the C# code is doing. For i = 3, the C# code would
return "D", not "A3".

Mike

Andrew Morton

unread,
Nov 19, 2009, 8:27:41 AM11/19/09
to
Family Tree Mike wrote:
> "Andrew Morton" wrote:
<rubbish>

> But that is not what the C# code is doing. For i = 3, the C# code
> would return "D", not "A3".

At least I've learnt something new today :-)

Andrew


Herfried K. Wagner [MVP]

unread,
Nov 21, 2009, 2:49:38 PM11/21/09
to
yxq schrieb:

What about '... = ChrW(AscW("A"c) + i)'?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

0 new messages