Mostly technical stuff with some interesting moments of life

Funny Infinite Loop with C#

No comments
What will happen when you run the following C# code? It's a never ending loop. Oh! really? yea, note the "Name" inside set method. I have used uppercase N. Now it will call setter recursively.

Interesting isn't it? :)


public class Person
{
private String name;
public String Name
{
set
{
System.Console.WriteLine("assigning wow");
Name = value;
}
}
}


public class Hello
{
static void Main()
{
Person person = new Person();
person.Name = "wow";
}
}

No comments :

Post a Comment