Search code examples
c#delphitlist

What is the C# equivalent of Delphi's TList?


In Delphi Programming, I have a class and store instances of this class in a list, with this code:

type
    TMyClass = class
    public
        name: String;
        old: Integer;
        anx: boolean;
    end;

...

function x(aList: TList): String;
var
    aObj: TMyClass;
    i: Integer;
begin
    for i:= 1 to aList.Count do
    begin
        aObj := aList[i-1];
    end;
end;

How can I do this in C#?

How do I write a TList equivalent in C# and let my class receive a TList?


Solution

  • //this is the class with fields.
    public class TMyClass
    {
        public String Name;
        public int old;
        public bool anx;
    }
    
    //this is the class with properties.
    public class TMyClass
    {
        public String Name { get; set; };
        public int old { get; set; };
        public bool anx { get; set; };
    }
    
    public string x(List<TMyClass> list)
    {
        TMyClass aObj;
        for(int i = 0; i++; i < list.Count)
        {
            aObj = list[i];
        }
        //NEED TO RETURN SOMETHING?
    }
    

    Here is a translation of your class and function. But I do believe your function needs to return something...