![](/img/trans.png)
[英]WPF how to bidirectionally link a checkBox to a class member AND to another static variable
[英]How to access member of a static class which is inside another static class
我有以下課程結構
public class MainClass
{
private static class Class1
{
private static class Class2
{
public const int Id = 2;
}
}
public void getId()
{
// I want to access Id here
}
}
現在我要訪問Class2內的變量Id
我試過像Class1.Class2.Id;
但這不起作用
我做錯了什么?
如果要從Class1
外部訪問此文件,則需要將訪問修飾符從private
更改為public
(可從任何地方訪問)或internal
(可從程序集訪問)。
public class MainClass
{
private static class Class1
{
// note the modifier change for Class2
public static class Class2
{
public const int Id = 2;
}
}
public void getId()
{
var id = Class1.Class2.Id;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.