私はクラス名がDriver
で、オブジェクトは20個あります。オブジェクトクラスの変数の1つが変数値。私はクラスのオブジェクトを変更するだけで、ウィンドウコードのような20のコードを持っています、そして、私はそれを簡単にするためにこれをしたいと思います。クラスの1つのオブジェクトに変数のX値があることを検出するには
public class Driver
{
public float Position;
public float DriverID;
public float TeamID;
public float TyreCompound;
public float BestLap;
public static Driver van = new Driver(0, 0, 0, 0, 0);
public static Driver ric = new Driver(0, 0, 0, 0, 0);
public static Driver vet = new Driver(0, 0, 0, 0, 0);
public static Driver rai = new Driver(0, 0, 0, 0, 0);
public static Driver gro = new Driver(0, 0, 0, 0, 0);
public static Driver eri = new Driver(0, 0, 0, 0, 0);
public static Driver per = new Driver(0, 0, 0, 0, 0);
public static Driver alo = new Driver(0, 0, 0, 0, 0);
public static Driver str = new Driver(0, 0, 0, 0, 0);
public static Driver mas = new Driver(0, 0, 0, 0, 0);
public static Driver mag = new Driver(0, 0, 0, 0, 0);
public static Driver kvy = new Driver(0, 0, 0, 0, 0);
public static Driver hul = new Driver(0, 0, 0, 0, 0);
public static Driver pal = new Driver(0, 0, 0, 0, 0);
public static Driver oco = new Driver(0, 0, 0, 0, 0);
public static Driver ves = new Driver(0, 0, 0, 0, 0);
public static Driver ham = new Driver(0, 0, 0, 0, 0);
public static Driver sai = new Driver(0, 0, 0, 0, 0);
public static Driver bot = new Driver(0, 0, 0, 0, 0);
public static Driver weh = new Driver(0, 0, 0, 0, 0);
public Driver(float position, float driverid, float teamid, float tyre, float bestlap)
{
Position = position;
DriverID = driverid;
TeamID = teamid;
TyreCompound = tyre;
BestLap = bestlap;
}
public void SetData(float position, float driverid, float teamid, float tyre, float bestlap)
{
Position = position;
DriverID = driverid;
TeamID = teamid;
TyreCompound = tyre;
BestLap = bestlap;
}
}
ウィンドウで
if (App.Driver.van.Position == 2)
{
TowerSecondName.Source = new BitmapImage(new Uri(@"/Images/Drivers/driver_" + (App.Driver.van.DriverID) + ".png", UriKind.Relative));
TowerSecond.Source = new BitmapImage(new Uri(@"/Images/TeamColours/" + (App.Driver.van.TeamID) + "Opa" + ".png", UriKind.Relative));
TowerSecondTyre.Source = new BitmapImage(new Uri(@"/Images/TyreIcons/" + (App.Driver.van.TyreCompound) + ".png", UriKind.Relative));
}
あなたの質問は明確ではありません...あなたが望むものを指定してください... – Arvindsinc2
'Driver'タイプのすべての静的フィールドを反復処理し、' Driver'タイプのものを検索する方法をお探しですか?特定の値?もしそうなら、あなたは[リフレクションを使ってすべての静的プロパティとクラスの値を取得する方法](https://stackoverflow.com/q/12474908/3744182)から始めることができます。 – dbc
"クラスのオブジェクト変数の1つ"が意味をなさないとき。あなたが念頭に置いている事例の具体例を挙げてください。コンクリート、特定、明確。あなたがしようとしていることを伝えることができない場合、誰もあなたを助けません。 –