.NET Answers

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

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!

How Generics Work

June 16, 2008 By: Dave Category: none

One of my fundamental beliefs about programming is that the best programmers understand what’s actually happening under the hood. This is why it is beneficial to look at the code for the .NET framework. Once you understand what’s going on, you have a better understanding of what you can and cannot do. Generics are one of those language features where it helps to understand what’s happening under the hood in order to use the feature to its full potential. To fully understand, we need a bit of a history lesson, so we need to visit our friend C++.

(more…)

FormView Edit and Add

May 12, 2008 By: Dave Category: none

The FormView generally makes editing a record at a time pretty easy.  However, one of the biggest problems I’ve seen with this control is that there is no way of telling the FormView to use the same template for both Add and Update.  My experience has been that most of the time, Add and Update look exactly the same, or enough the same that you could use one template and hide the inappropriate controls in the template.

(more…)

Reflection From a DLL and Serialization

April 30, 2008 By: Dave Category: none

Last week, we finished up our main series on reflection.  For most people, what we covered is all they will ever need.  However, there are a few other things I’ve needed to know due mainly to the fact that I was using reflection from a DLL instead of an EXE

When I wrote VSS.NET, which was my first .NET application, allow Visual SourceSafe to be used over the Internet, I wanted to implement the SCC api.  This is the API that allows you to use VSS from the IDE.  For some reason that I can’t remember now and isn’t important to this discussion, I needed to use reflection from the DLL that the SCC interface was calling.  This posed two problems.

(more…)

WinForms - Database Changes not sticking.

April 28, 2008 By: Dave Category: none

Saturday afternoon I spent trying to get a Windows Forms application to add data to a database.  It all seemed to work correctly.  Add changes, no errors.  Close window, open window.  Yep changes are there.  Close application, re-run application.  Yep, changes still there.  Make a change to the code, re-run.  No data.

(more…)