Showing posts from October, 2007

String.Empty vs ""

So I've always heard you should use String.Empty vs "" the dreaded blank string in C#. So I decided to write a little test program to find out. It simply takes a string variable and assigns it to "" or String.Empty. I do this 1 million times each and time how many milliseconds it takes to do that assignment. My system is a p4 1.5 GHz RAM running .net 2.0. Source code can be sent upon request. The results are surprising and can be seen below. Other then the first run the String.Empty beat the "" by a few milliseconds. Hardly the creaming I've read about. But perhaps if you were doing some severe number crunching you would notice a difference. However this test is hardly definitive and should probably be run several more times and had the numbers aggregated. I've run the app a lot more since yesterday but only added one more screenshot. I may just post the screen UI and then keep track of the results in a spreadsheet or modify the app

Nested Repeaters in ASP.NET

Ok so you may want to show some hierarchical data using repeaters. This means nesting a repeater in a repeater. This is fine but it takes some work in the code behind. First off create the main repeaters ItemDataBound event. In that event use the following code. I am old school so forgive me any syntax. For this code to work you must originally bind a DataSet to the parent repeater with a data relation connecting the parent/child tables. So somewhere (I do mine in page load) bind the entire dataset to the repeater: RepeaterCapabilities.DataSource = someDataSet; RepeaterCapabilities.DataBind(); Then put the following code in the repeaters ItemDataBound event protected void RepeaterCapabilities_ItemDataBound( object sender, RepeaterItemEventArgs e ) { Repeater rptActivities; DataRowView drv; // get the row behind the databind drv = e.Item.DataItem as DataRowView; if( drv != null ) { // get the nested repeate

Reading & writing connection strings to an app.config file in C# 2.0

Ok after working on this for a bit this morning I am sharing my experience with the world. I needed to read and write some connection strings found in an app.config file I was using in a small C# .NET 2.0 application. First you must have a reference to the System.configuration dll in your project and use the System.Configuration namespace in any C# files you want to do this stuff in. This sample assumes you have your connection strings in a connectionString section of an app.config file. Reading the connection string: ConfigurationManager.ConnectionStrings["Connection Name"].ConnectionString Writing the connection string: // get the config file for this application Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None ); // set the new values config.ConnectionStrings.ConnectionStrings["Connection Name"].ConnectionString = "Connection String Value"; // save and refresh the config file confi