Categories: Blog

Devscovery Ponderrings

Last week was very hectic with Devscovery Redmond in full swing. It was a great event and I really think I connected with the audience. I had a lot of conversations between sessions and at the end of each day. In particular, during the reception, I had a whiteboard session where I was with 4 attendees architecting their client/server/web service architecture – what could be more fun than this?!
 
I also had 2 questions from attendees that I thought were interesting and caused me to write some code to verify how things worked. The first question was about delegates. The attendee asked if delegates work when the callback is to a virtual method. That night, I coded up the code below to test things out. Without peeking, can you guess what the output from this code is? “B: 34“ or “D: 34“?
 
using System;
 
class B {
   delegate String Del(Int32 x);
 
   static void Main() {
      B b = new D();
      Del del = new Del(b.M);
      Console.WriteLine(del(34));
   }
   protected virtual String M(Int32 x ) {
      return “B: ” + x;
   }
}
 
class D : B {
   protected override String M(Int32 x) {
      return “D: ” + x;
   }
}
 
The answer is “D: 34” as the delegate contains a reference to a D object and calling the instance method M DOES in fact happen polymorphically.
 
The second question was about the difference between System.Exception’s Message property and its ToString method. I had forgotten what ToString on an Exception actually does so I used Lutz’s Reflector to check the code for these two members. The Message property returns just the exception’s message while ToString returns the class name, the Message text, the Stack trace, and repeats this for all nested exceptions too.
 
My next event is Devscovery Atlanta where, I’m sure I’ll have just as much fun AND, I hope I learn some more while I’m there.
Jeffrey Richter

Recent Posts

8-Step AWS to Microsoft Azure Migration Strategy

Microsoft Azure and Amazon Web Services (AWS) are two of the most popular cloud platforms.…

1 week ago

How to Navigate Azure Governance

 Cloud management is difficult to do manually, especially if you work with multiple cloud…

3 weeks ago

Why Azure’s Scalability is Your Key to Business Growth & Efficiency

Azure’s scalable infrastructure is often cited as one of the primary reasons why it's the…

1 month ago

Unlocking the Power of AI in your Software Development Life Cycle (SDLC)

https://www.youtube.com/watch?v=wDzCN0d8SeA Watch our "Unlocking the Power of AI in your Software Development Life Cycle (SDLC)"…

2 months ago

The Role of FinOps in Accelerating Business Innovation

FinOps is a strategic approach to managing cloud costs. It combines financial management best practices…

2 months ago

Azure Kubernetes Security Best Practices

Using Kubernetes with Azure combines the power of Kubernetes container orchestration and the cloud capabilities…

2 months ago