static initialization of a class in C#

I have a need to convert/upgrade my data structure struct to a class and have a question: Can I statically initiate my class like the struct? If so, any guidance of how to do it would be highly appreciate. Below is the definition of my struct:

typedef struct t
{
   struct t *next;
   int otherfield;
} T

T r1[]={{0,1},{0,2}};
T s1[]={{r1,3},{0,4}};

My converted class looks like

class T
{
  class T next;
  int otherfield;
}
List<T> r1;
List<T> s1;

How do I statically initiate r1, s1. Standard initialization thru a constructor may not work as I have hundred of these struct and they were all initialized statically.

Thanks,

Answers


Can't you just do the following?

class T
{
    public T next;
    public int otherfield;
    public T( T next, int otherfield )
    {
        this.next = next;
        this.otherfield = otherfield
    }
}

T[] r1 = new T[]{ new T( null, 1 ), new T( null, 2 ) };
T[] s1 = new T[]{ new T( r1[0], 3 ), new T( null, 4 ) };

Edit: if you want to do it with a List then you could do the following:

List< T > r1 = new List< T >( new T[]{ new T( null, 1 ), new T( null, 2 ) } );
List< T > s1 = new List< T >( new T[]{ new T( r1[0], 3 ), new T( null, 4 ) } );

Need Your Help

directshow : display graph result onto wpf window

c# wpf directshow directshow.net

I am a beginner directshow programmer I am trying to make WPF App that contain (live feed) from certain web camera

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.