Windows Forns变量继承 [英] Windows Forns variables inheritance

查看:41
本文介绍了Windows Forns变量继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题!它很简单,很容易解决!

我有一个带有某些字段的Form1

Hi, I have a small question! It is simple and easily solved!

I have a Form1 with some fields

private int selectedSkolotajuID = 0;
        private int selectedSkolenuID = 0;
        private int selectedTestID = 0;



然后我创建了新的Windows Form2

如何在新的Form2中继承这些字段

:)



And I created new windows form Form2

how I can inherit those fields in my new Form2

:)

推荐答案

否.它们是private.如果希望它们在派生类中可访问,则将它们标记为protected,对于相同的名称空间,请使用internal,对于任何使它们命名为public的人.

但是,最好的方法是将它们保留为private并创建更多打开的属性来访问它们.这样,您可以更改表单内部而不会影响外部元素.
例如:
No. They are private. If you want them to be accessible in derived classes, then mark them as protected, for the same namespace use internal and for anyone make them public.

However, the best way to do it is to leave them as private and create more open properties to access them. That way you can change your form internals without affecting outside elements.
For example:
private int selectedSkolotajuID = 0;
public int SelectedSkolotajuID
   {
   get { return selectedSkolotajuID; }
   set {selectedSkolotajuID = value;}
   }


这篇关于Windows Forns变量继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆