Need help translating this Java code into a C# script

Hello everyone!

I’d like to ask for help with a script here with which I am stuck for several hours now.

Basically this is the code written in Java:

public class A {
	private int i;
	private int j;
	
	public A() {
		i = 1;
		j = 2;
	}
	
	public int getI() {
		return i;
	}
	
	public int getJ() {
		return j;
	}
}
import java.util.ArrayList;

public class B {
	private int x;
	private int y;
	private ArrayList<A> list = new ArrayList<>();
	
	public B() {
		for (int i = 0; i < 16; i++) {
			A temp = new A();
			list.add(temp);
		}
	}
	
	public A getSelected() {
		for (A elem : list) {
			if((elem.getI() == x)  (elem.getJ() == y)) {
				return elem;
			}
		}
		return null;
	}
}

Now my problem is that I cannot figure out how to tranlate this into a C# script and I have tried out quite a lot of things by now.
The main focus lies on the “getSelected” method in class B.
If someone could show me how it’s done that would be really great.

Thanks in advance for any helping replies.
Regards

Here is class A:

public class A {

    private int i;
    private int j;    

    // Getters (Might not want to use "I" as and identifier as it is too similar to a lower-case L in some fonts)
    public int getI {
        get{return i;}
    }   
    public int getJ {
        get{return j;}
    }

    // Constructor...
    public A() {
        i = 1;
        j = 2;
    }

    // Or public method
    public void A() {
        i = 1;
        j = 2;
    }
}

Here is class B:

using System.Collections.Generic; 

public class B {

    private int x;
    private int y;
    private List<A> list = new List<A>();   

    // Constructor
    public B() {
        for (int i = 0; i < 16; i++) {
            A temp = new A();
            list.add(temp);
        }
    }
    public A getSelected() {
        A returnElem = null;
        foreach(A elem in list) {
            if((elem.getI == x)  (elem.getJ == y)) {
                returnElem = elem;
                break;
            }
        }
        return returnElem;
    }
}

That should be the correct translation, but I didn’t test it. Hope this is what you were looking for, if you have questions let me know.

thank you very much! :slight_smile:

by now I figured something out by myself and although I cant tell anymore what exactly I did it somehow worked.
but luckily your efford wasnt a waste since I could optimise some things :slight_smile: