Hi,
It seems that you are missing some .NET/OOP basics.
All classes (except string) are reference type, on the other hand, structures are value type.
Both List and Array are reference type so using an array instead of a list won't solve your problem.
If I understand what you're tying to do: populate a list of a 'A' type using the default (without arguments) 'A' constructor to create instances of 'A' (I suppose you set each 'A' instance properties from the class where the list is build).
so, IMO your problem is due to the way you create each 'A' instance. In the class where you populate the list, you need to explicitly create a New instance of 'A' for each object
Here's a little sample (not related to AutoCAD):
C#
using System;
using System.Collections.Generic;
namespace GenericListSample
{
class Program
{
static void Main()
{
List<A> Alist = new List<A>();
A tempA = new A();
tempA.Name = "foo";
tempA.Index = 1;
tempA.Date = new DateTime(2012, 11, 10);
tempA.Position = new double[2] { 0.0, 0.0 };
Alist.Add(tempA);
tempA = new A();
tempA.Name = "bar";
tempA.Index = 2;
tempA.Date = new DateTime(2012, 11, 12);
tempA.Position = new double[2] { 10.0, 20.0 };
Alist.Add(tempA);
tempA = new A();
tempA.Name = "baz";
tempA.Index = 3;
tempA.Date = new DateTime(2012, 11, 18);
tempA.Position = new double[2] { 50.0, 30.0 };
Alist.Add(tempA);
foreach (A a in Alist)
{
Console.WriteLine("Name: {0}, Index: {1}, Date: {2}, Position: {3}, {4}",
a.Name, a.Index, a.Date, a.Position[0], a.Position[1]);
}
}
}
class A
{
public string Name { get; set; } // value type
public int Index { get; set; } // value type
public DateTime Date { get; set; } // reference type
public double[] Position { get; set; } // reference type
}
}
VB
Imports System
Imports System.Collections.Generic
Namespace GenericListSample
Class Program
Public Shared Sub Main()
Dim Alist As New List(Of A)()
Dim tempA As New A()
tempA.Name = "foo"
tempA.Index = 1
tempA.TheDate = New DateTime(2012, 11, 10)
tempA.Position = New Double(1) {0.0, 0.0}
Alist.Add(tempA)
tempA = New A()
tempA.Name = "bar"
tempA.Index = 2
tempA.TheDate = New DateTime(2012, 11, 12)
tempA.Position = New Double(1) {10.0, 20.0}
Alist.Add(tempA)
tempA = New A()
tempA.Name = "baz"
tempA.Index = 3
tempA.TheDate = New DateTime(2012, 11, 18)
tempA.Position = New Double(1) {50.0, 30.0}
Alist.Add(tempA)
For Each a As A In Alist
Console.WriteLine("Name: {0}, Index: {1}, Date: {2}, Position: {3}, {4}", _
a.Name, a.Index, a.TheDate, a.Position(0), a.Position(1))
Next
End Sub
End Class
Class A
Private m_Name As String ' value type
Private m_Index As Integer ' value type
Private m_Date As DateTime ' reference type
Private m_Position As Double() ' reference type
Public Property Name() As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
Public Property Index() As Integer
Get
Return m_Index
End Get
Set(value As Integer)
m_Index = value
End Set
End Property
Public Property TheDate() As DateTime
Get
Return m_Date
End Get
Set(value As DateTime)
m_Date = Value
End Set
End Property
Public Property Position() As Double()
Get
Return m_Position
End Get
Set(value As Double())
m_Position = value
End Set
End Property
End Class
End Namespace
Another way is to make 'A' type a structure rather than a class. As a structure is a value type, a new instance will be implictly created.
Here's the same sample as upper using a structure:
C#
using System;
using System.Collections.Generic;
namespace GenericListSample
{
class Program
{
static void Main()
{
List<B> Blist = new List<B>();
B tempB = new B();
tempB.Name = "foo";
tempB.Index = 1;
tempB.Date = new DateTime(2012, 11, 10);
tempB.Position = new double[2] { 0.0, 0.0 };
Blist.Add(tempB);
tempB.Name = "bar";
tempB.Index = 2;
tempB.Date = new DateTime(2012, 11, 12);
tempB.Position = new double[2] { 10.0, 20.0 };
Blist.Add(tempB);
tempB.Name = "baz";
tempB.Index = 3;
tempB.Date = new DateTime(2012, 11, 18);
tempB.Position = new double[2] { 50.0, 30.0 };
Blist.Add(tempB);
foreach (B a in Blist)
{
Console.WriteLine("Name: {0}, Index: {1}, Date: {2}, Position: {3}, {4}",
a.Name, a.Index, a.Date, a.Position[0], a.Position[1]);
}
}
}
struct B
{
public string Name { get; set; } // value type
public int Index { get; set; } // value type
public DateTime Date { get; set; } // reference type
public double[] Position { get; set; } // reference type
}
}
VB
Imports System
Imports System.Collections.Generic
Namespace GenericListSample
Class Program
Public Shared Sub Main()
Dim Blist As New List(Of B)()
Dim tempB As New B()
tempB.Name = "foo"
tempB.Index = 1
tempB.TheDate = New DateTime(2012, 11, 10)
tempB.Position = New Double(1) {0.0, 0.0}
Blist.Add(tempB)
tempB.Name = "bar"
tempB.Index = 2
tempB.TheDate = New DateTime(2012, 11, 12)
tempB.Position = New Double(1) {10.0, 20.0}
Blist.Add(tempB)
tempB.Name = "baz"
tempB.Index = 3
tempB.TheDate = New DateTime(2012, 11, 18)
tempB.Position = New Double(1) {50.0, 30.0}
Blist.Add(tempB)
For Each a As B In Blist
Console.WriteLine("Name: {0}, Index: {1}, Date: {2}, Position: {3}, {4}", a.Name, a.Index, a.TheDate, a.Position(0), a.Position(1))
Next
End Sub
End Class
Structure B
Private m_Name As String ' value type
Private m_Index As Integer ' value type
Private m_Date As DateTime ' reference type
Private m_Position As Double() ' reference type
Public Property Name() As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
Public Property Index() As Integer
Get
Return m_Index
End Get
Set(value As Integer)
m_Index = value
End Set
End Property
Public Property TheDate() As DateTime
Get
Return m_Date
End Get
Set(value As DateTime)
m_Date = value
End Set
End Property
Public Property Position() As Double()
Get
Return m_Position
End Get
Set(value As Double())
m_Position = value
End Set
End Property
End Structure
End Namespace