I'm trying to implement a variable from an interface and I can't do it... with functions it works great but with variables it gets stuck as if I were in an infinite loop.
///--------------------------------------------------
public interface Interface
{
string Func();
int id {get;set;}
}
///--------------------------------------------------
public class Implemetador : Interface
{
public Implemetador(){}
string Func() //-->sin problemas
{
return "id=";
}
public int id //-->bloqueado
{
set{id = value;}
get{return 55;}
}
}
///--------------------------------------------------
public class Test
{
static void Main()
{
Implemetador i = new Implemetador();
Console.Write(i.Func() + i.id);
}
}
///--------------------------------------------------
The way to implement it I got from here page 16.
https://profesorezequielruizgarcia.files.wordpress.com/2014/10/poo-csharp.pdf
I think they are notes from some university and it doesn't give errors when compiling so I don't understand why it doesn't work...
Any idea what it could be?
This code creates a recursive call that will never stop
The call to set is also a call to the property
id
I recommend changing the implementation of the property to the following: