R
Rene
It seems simple enough to use objects initializers to initialize object
properties and collection intitializers to initialize collection, what I
have not been able to figure out is a way to initialize object properties
and collections at the same time.
By the way, I don't have a need to do that, I am simply curious if that is
doable or not. See snippet below.
Thank you.
class Program
{
static void Main(string[] args)
{
// Initialize property no problem.
var col2 = new MyCollection() { SomeProp = 123 };
// Initialize collection no problem.
var col1 = new MyCollection() { 1, 2, 4 };
// Initialize proerty and collection how????
//var p = new Pupu() {{ X = 123 }{1,2,3}};
}
}
class MyCollection : System.Collections.IEnumerable
{
private int m_SomeProp;
public int SomeProp
{
get { return m_SomeProp; }
set { m_SomeProp = value; }
}
internal void Add(object i)
{
}
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator()
{
// Prevent compiler error.
return null;
}
}
properties and collection intitializers to initialize collection, what I
have not been able to figure out is a way to initialize object properties
and collections at the same time.
By the way, I don't have a need to do that, I am simply curious if that is
doable or not. See snippet below.
Thank you.
class Program
{
static void Main(string[] args)
{
// Initialize property no problem.
var col2 = new MyCollection() { SomeProp = 123 };
// Initialize collection no problem.
var col1 = new MyCollection() { 1, 2, 4 };
// Initialize proerty and collection how????
//var p = new Pupu() {{ X = 123 }{1,2,3}};
}
}
class MyCollection : System.Collections.IEnumerable
{
private int m_SomeProp;
public int SomeProp
{
get { return m_SomeProp; }
set { m_SomeProp = value; }
}
internal void Add(object i)
{
}
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator()
{
// Prevent compiler error.
return null;
}
}