.NET Answers

ASP.NET, HTML, CSS, Visual Studio, CSharp, VB.NET and other programming items of interest.
Subscribe

Archive for June 23rd, 2008

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

June 23, 2008 By: Dave Category: none

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?

(more…)

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!