Archive for February, 2009

Create and Initialize List of Strings

In .NET you can create and initialize an Array of strings or a generic List<string> in C# using a comma-delimited list.  However, the only way I’ve found so far to do the same thing with a generic List(Of String) in VB.NET is to use an Array of strings as a parameter for the List like this.

VB.NET

Dim states As List(Of String) = New List(Of String) _
    (New String() {"AL", "AZ", "CA", "CO", "NV", "OK"})


C#

List<string> states =
     new List<string>() { "AL", "AZ", "CA", "CO", "NV", "OK" };

Current ASPX Page Name

Get the name of the current ASP.NET page.

string path = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
string name = System.IO.Path.GetFileName( path );