How can i pass/use private variables froma class in Form1 with a public function?

前端 未结 5 755
粉色の甜心
粉色の甜心 2021-01-27 05:28

I don\'t want to make a new instance of Form1 in the class, and i dont want to use static.

I have these two variables which are private in the top of the cl

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-27 05:54

    You can not use private fields of a class inside another (cause Form is just another class). What you can do, if limiting the accessibility is important to you, is using internal keyword, instead of private. But it will work only if both classes are in the same assembly.

    internal List Point_X = new List();
    internal List Point_Y = new List();
    

    To be clear it's always a good to have some property or method that "wraps" access to the private fields, but as much as I understood it's not something you want to avoid, for some reason.

提交回复
热议问题