Home » 2008 » December (Page 2)

GridViews – Multiple Rows Per Record

G04B0069 I don’t know about you, but I’ve had several occasions where I’ve needed to use the simplicity of the GridView control in ASP.NET.  DataBinding, Paging, Sorting, etc.  But I’ve also wanted to stack the information for a record in multiple rows.

Most of the time this happens when I need to display data that would take up two or three times as much of the width as my layout will allow.

The solution to this problem is quite simple: Use templated columns and Literal controls.

Continue reading “GridViews – Multiple Rows Per Record”

Unsafe Mode in C#

tp_vol4_006 One of the “advantages” of using CSharp instead of VB.NET is that if programmers want to, they have the option of bypassing the memory management of .NET and working with memory directly.  This is called “unsafe” mode.

While I will show you how to use this keyword, I have to tell you up front that I’ve been using CSharp since Beta 2 of .NET 1.0 and I’ve NEVER needed to switch into unsafe mode to do any of the work that I’ve done.

I’ve even written code that bridged down to some unmanaged C++ code and still have not needed to use unsafe mode.

Continue reading “Unsafe Mode in C#”

CSharp checked and unchecked

coordonnées GPS:   4°315´S     55°719°E When you create a project in Visual Studio, by default, numbers can be added, multiplied, divided or subtracted in such a way as to create a number too big for the variable that is holding the number.

You can change this at the project level for a Windows exe project by going to project properties, selecting the build tab, clicking the “Advanced” tab and checking the checkbox, “Check for arithmetic overflow/underflow.”

Continue reading “CSharp checked and unchecked”

Using Sealed in CSharp

misc_vol2_023 Another potentially useful but not very popular keyword in CSharp is the sealed keyword.  While not a keyword that you will need to use often, it is a critical keyword for framework developers who want to have tighter control over how their classes get used.

The two primary uses of the sealed keyword are as they apply to the class and as they are applied to elements of the class.

Continue reading “Using Sealed in CSharp”

Delegates in .NET

hand-010 I received the following question:

What is a delegate?  What problem does it solve?  and When might I use a delegate?

A delegate is essentially a function pointer.  We have used function pointers in various scenarios in the past to solve the problem of needing to execute user-defined code inside of another function or to fire events using the observed/observable programming pattern.

The problem we’ve always had with function pointers in the past is that there has never been any type safety.  If I had a variable that was supposed to point to a function, I could assign it any function.  So if the function the code is expecting returns a string and takes an integer and a string as parameters, I could assign the variable a function that returned nothing (void) and passed nothing.  My code would compile, but when I got to that function, the chances are my code would blow up on me.

Continue reading “Delegates in .NET”