Sometimes we don't want to instantiate the class when creating this class array. there exist pointer array in c or c++. example(c++):
class Example
{
}
void main()
{
Example* PointerArray[5]; // uninstantiated
PointerArray[0] = new Example; // instantiate now
}
but we have to instantiate the class in C# when creating array.
class OuterEx
{
class InnerEx
{
}
static void main()
{
InnerEx[] PointerArray = new InnerEx[5];
}
}
for reference is not an independent type in C# and we don't want to use pointer(unsafe code) in most program;
so i have one idea to solve this problem:
class OuterEx
{
class InnnerEx
{
}
class RefEx
{
InnerEx Ref;
}
static void main()
{
RefEx[] RefArray = new RefEx[5];
RefArray[0].Ref = new InnerEx();
}
}
If we don't want to write .Ref every time, we have to write a type convertion method. after all it's real inconvinient.
Anybody can tell me how to solve this problem or there exist any solution i havn't found in C#.
class Example
{
}
void main()
{
Example* PointerArray[5]; // uninstantiated
PointerArray[0] = new Example; // instantiate now
}
but we have to instantiate the class in C# when creating array.
class OuterEx
{
class InnerEx
{
}
static void main()
{
InnerEx[] PointerArray = new InnerEx[5];
}
}
for reference is not an independent type in C# and we don't want to use pointer(unsafe code) in most program;
so i have one idea to solve this problem:
class OuterEx
{
class InnnerEx
{
}
class RefEx
{
InnerEx Ref;
}
static void main()
{
RefEx[] RefArray = new RefEx[5];
RefArray[0].Ref = new InnerEx();
}
}
If we don't want to write .Ref every time, we have to write a type convertion method. after all it's real inconvinient.
Anybody can tell me how to solve this problem or there exist any solution i havn't found in C#.