Home » Posts tagged "convert"

AS is in CSharp too.

Many CSharp programmers are surprised to find that CSharp has an AS keyword that looks remarkably similar to VB.NET’s AS keyword.  And while on the surface it looks similar to what AS does in VB.NET, it is quite a bit different.

To start with, you can’t declare a variable with the AS keyword.  But you can assign to a variable using the AS keyword, like so:

Continue reading “AS is in CSharp too.”

Why you can’t cast an integer to a string.

I saw this question last Thursday on Channel 9 that I’ve heard before. My guess is that there are enough people who have the same question that it’s worth addressing.

I know there’s probably a really good reason for this, but I can’t think of what it is, and it keeps bugging me. Why can’t you do
int x = 10;
string y = (string)x;
in C#? I mean, you could simply use x.ToString(), but why doesn’t the explicit cast do the same?

Continue reading “Why you can’t cast an integer to a string.”