Related Entries

Is ADO.Net portable?
Oracle with C#
Slashdot: Java vs .Net
Variable number of function arguments in C#
Mozilla intentionally breaks ASP.Net pages?

« Mozilla intentionally breaks ASP.Net pages?
» Toshiba e355

C# day 3

Notes from third day of learning C#
  1. Regarding Kasia's comments on string abuse, I'd say C# has a nice debugging solution that can't be done as cleanly in Java. You can easily create a Trace() that take a variable-length list of arguments, checks each for null and handles it nicely.

    Something like this (which will looks junky, since html is disabled -- maybe it would be better to have a limited subset?):

    public static string Trace( object sender, string msg, params Object[] things )
    {
    if( Verbose || Debugging )
    {
    try
    {
    if( sender == null )
    sender = System.AppDomain.CurrentDomain;
    System.Diagnostics.StackFrame frame = new System.Diagnostics.StackTrace().GetFrame(1);
    if(frame.GetMethod().Name == "Trace")
    frame = new System.Diagnostics.StackTrace().GetFrame(2);
    System.Text.StringBuilder text = new System.Text.StringBuilder( sender.GetType().Name );
    text.Append( "." );
    text.Append( frame.GetMethod().Name );
    text.Append( "(): " );

    if( things.Length > 0 )
    for( int i = 0; i ":things[i].ToString() );


    text.Append(msg);
    msg = text.ToString();

    System.Diagnostics.Trace.WriteLine( msg );

    if(Logging)
    Log(msg);
    }
    catch
    {
    // can't trace!
    }
    }
    return msg;
    }

    Posted by: Matt Gerrans on September 22, 2003 04:48 PM
//-->