EDIT: In considerations i didn't have access to list
EDIT: I changed example to more advanced
EDIT: Fixed example ;P
EDIT: Again edited I'm sure that i got vote down cause you guys didn't understand orgin of my considerations. I know it is posible with pointers in C++ but not sure it is still posible in C#. And i didnt ask cuase i don't know how to change element in List! I just want to make it without access to that LIST! This is only example cuase real live example is to complicated to introduce here...
I Wonder if it's posible to do something like this class Foo { public int foo = 100; EventHandler something;
public Foo()
{
something += smth;
}
public void doSmth()
{
something(this, EventArgs.Empty);
}
public static void smth(object sender, EventArgs e)
{
sender = new Foo();
}
}
class Boo : Foo
{
EventHandler<EventArgs> something;
public Boo()
{
foo = 1;
something += smth;
}
}
static void Main(string[] args)
{
List<Foo> list = new List<Foo>();
Foo foo = new Boo();
list.Add(foo);
foreach (Foo f in list)
f.doSmth();
foreach (Foo f in list)
Console.WriteLine(f.foo);
Console.ReadKey();
}
My output is 1 but i want to get 100. It is posible to change object from list by its reference ?