Interfaces collection in C#
Forums:
var rows = new INamed[] {
new Flower {Name = "Rose"},
new City {Name = "Rome"},
new Star {Name = "Sirius"} };
var list = string.Join(", ", rows.Select(r => r.Name));
//list is Rose, Rome, Sirius
interface INamed {
string Name { get; set; }
}
struct Flower : INamed {
public string Name { get; set; }
}
struct City : INamed {
public string Name { get; set; }
}
struct Star: INamed {
public string Name { get; set; }
}
- Log in to post comments