Interfaces with structs, by reference using Generics
Posted
by Fraga
on Stack Overflow
See other posts from Stack Overflow
or by Fraga
Published on 2010-03-13T02:57:39Z
Indexed on
2010/03/13
3:07 UTC
Read the original article
Hit count: 356
I can't pass by reference an interface with a struct in it, what am I doing wrong?
Here is the example code:
class Processor<T>
where T : new()
{
public Processor()
{
Data = new T();
}
public T Data;
}
class PeriodsProcessor : Processor<Periods>
{
public PeriodsProcessor()
{
DataBase DB = new DataBase();
Console.WriteLine(Data.Value);
DB.ModifyData<Period>(Data);
Console.WriteLine(Data.Value);
Console.ReadLine();
}
}
public class Period
{
public string Name;
}
public interface IDataTable<T>
{
string Value { get; set; }
T Filter { get; set; }
}
[Serializable]
public struct Periods : IDataTable<Period>
{
public string Value { get; set; }
public Period Filter { get; set; }
}
public class DataBase
{
public void ModifyData<T>(IDataTable<T> data)
where T : new()
{
data.Value = "CHANGE";
}
}
class Program
{
static void Main(string[] args)
{
PeriodsProcessor PeriodsProcessor = new PeriodsProcessor();
}
}
© Stack Overflow or respective owner