[ad_1]
単純な文字列と数値データを格納するために、wpf プロジェクトにデータ C# クラスが必要です。 誰にも良い例やアイデアがありますか?
私が試したこと:
internal class Att { BillInfo Aug2022W = new BillInfo(91.93M, "August 2022");//the data in class object BillInfo Aug2022I = new BillInfo(66.00M, "August 2022");// form instantiating with BillInfo Sept2022W = new BillInfo(91.82M, "September 2022");// constructor from BillInfo Sept2022I = new BillInfo(66.00M, "September 2022");// BillInfo class BillInfo Oct2022W = new BillInfo(91.82M, "October 2022"); BillInfo Oct2022I = new BillInfo(66.00M, "October 2022"); BillInfo Nov2022W = new BillInfo(91.82M, "November 2022"); BillInfo Nov2022I = new BillInfo(66.00M, "November 2022"); BillInfo Dec2022W = new BillInfo(00.01M, "December 2022"); BillInfo Dec2022I = new BillInfo(66.00M, "December 2022"); BillInfo Jan2023W = new BillInfo(00.01M, "January 2023"); BillInfo Jan2023I = new BillInfo(00.01M, "January 2023"); BillInfo Feb2023W = new BillInfo(84.28M, "February 2023"); BillInfo Feb2023I = new BillInfo(00.01M, "February 2023"); BillInfo March2023W = new BillInfo(84.23M, "March 2023"); BillInfo March2023I = new BillInfo(60.32M, "March 2023"); BillInfo[] ArrayBillInfo = new BillInfo[16]; // making array of class objects public BillInfo RonsMethod() { ArrayBillInfo[0] = Aug2022W; // method to assign each bill object data to ArrayBillInfo[1] = Aug2022I; // the object array ArrayBillInfo[2] = Sept2022W; ArrayBillInfo[3] = Sept2022I; ArrayBillInfo[4] = Oct2022W; ArrayBillInfo[5] = Oct2022I; ArrayBillInfo[6] = Nov2022W; ArrayBillInfo[7] = Nov2022I; ArrayBillInfo[8] = Dec2022W; ArrayBillInfo[9] = Dec2022I; ArrayBillInfo[10] = Jan2023W; ArrayBillInfo[11] = Jan2023I; ArrayBillInfo[12] = Feb2023W; ArrayBillInfo[13] = Feb2023I; ArrayBillInfo[14] = March2023W; ArrayBillInfo[15] = March2023I; return ArrayBillInfo[15]; // return just the most recent array location } public BillInfo[] RonsMethod2() // return whole object array { return ArrayBillInfo; }}} internal class BillInfo { public decimal Amount { get; set; } // object for data object array public string Date { get; set; } public BillInfo(decimal amount, string date) { Amount = amount; Date = date; }}
解決策 1
アプリ全体でデータが共通している場合は、静的クラスを使用します。 私は DataStore
それが何のためにあるのかを明確にするための接尾辞。 例えば:
C#
public static class AppDataStore { public ApplicationTheme Theme { get; set; } public UserProfile User { get; set; } {
アプリのどこからでもユーザーにアクセスするには、次のことを行う必要があります。
C#
string userName = AppDataStore.User.Name;
[ad_2]
コメント