在javascript中,我使用并创建对象来存储有关我的程序的信息,如下所示:
var information = {
page1 : {
info : "this is some information about page 1",
time : 1491319773386
},
page2 : {
info : "this is some information about page 2",
time : 1491319796452
}
};
csharp中是否有等价物?
像这样:
class Test {
public static Class pages = Class {
public static Class page1 = Class {
public static string info = "this is page1";
public static int date = 14487989879987;
}
public static Class page2 = Class {
public static string info = "this is page2";
public static int date = 14487989845344;
}
}
}
用法:
class Main {
public static void main(string[] args) {
Console.WriteLine(Test.pages.page1.info);
}
}
答案 0 :(得分:0)
为此我们通常使用类。 上课非常简单。
public class Information {
public string[] page1 = new string[2]{"this is ...", "..."};
public string[] page2 = new string[2]{"aaaa", "bbbb"};
}
你不一定需要使用string [] tho,在C#中有很多方法可以做到这一点。我希望这就是你要求的!
此致 realmaster42
答案 1 :(得分:0)
这可以使用彼此嵌套的static
类来完成:
public static class Test {
public static class pages {
public static class page1 {
public static string info = "this is page1";
public static int date = 14487989879987;
}
public static class page2 {
public static string info = "this is page2";
public static int date = 14487989845344;
}
}
}
这与您的示例相似,但更加整洁有效。