Puzzle 1: Passing reference types by value (Beginner)

by Geoffrey 29. March 2011 20:39

With this post I’ll start a series about programming puzzles and kata’s.

These small exercises will focus on the specific features of C#1,2 & 3.

Have fun…

 

What is the output of: ValueRef.Problem() ?

Can you explain why?

 

  1: public class ValueRef
  2: {
  3:         public static void Problem()
  4:         {
  5:             StringBuilder myStrBuilder = new StringBuilder("x");
  6:             AppendHello(myStrBuilder);
  7:             Console.WriteLine(myStrBuilder.ToString());
  8:             Console.ReadLine();
  9:         }
 10: 
 11:         static void AppendHello(StringBuilder builder)
 12:         {
 13:             builder.Append("hello");
 14:             builder = null;
 15:         }
 16: }
kick it on DotNetKicks.com

Tags: , ,

blog comments powered by Disqus

About the author

Geoffrey Vandiest

contact

View Geoffrey Vandiest's profile on LinkedIn

Follow me on twitter

Geoffrey Vandiest is a technical fellow who learned the art of programming at the age of 10 on a Philips MSX computer. He's skilled in the architecture and development on the Microsoft platform and started experimenting with the Microsoft .Net framework as from the Beta 1 in 2001. Since nearly a decade Geoffrey coaches development teams and base his management style on Agile principles.

 

Month List