我如何从另一个班级召唤一个班级

编程入门 行业动态 更新时间:2024-10-24 12:29:12
本文介绍了我如何从另一个班级召唤一个班级-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建一个类名称PersonalInfo.CS.我想将此类调用到另一个类,例如EmplInfoc.​​cs

I create one class name PersonalInfo.CS. i want to call this class to another class like EmplInfoc.cs

推荐答案

,您需要在EmplInfoc中创建PersonalInfo的实例,您可以使用new关键词.例如 you need to create an instance of PersonalInfo in your EmplInfoc you do that by using the new keyword. E.g. PersonalInfo personalInfo = new PersonalInfo(); personalInfo.APublicMethod();

但是,这是非常基础的,因此我认为您在这里不会获得满意的答案,因为对基础的解释要比对几行的解释要多.我建议您去书店找一本书.

This is very basic however, so I don''t feel you will get satisfying answers here as explaining the basics takes a bit more then a few lines of explanation. I suggest you go to a bookstore and find yourself a book.

我想这两个类都在同一个项目中定义. 您可以自由调用public的public 静态成员. 如果具有类型为PersonalInfo的对象(即PersonalInfo类的实例),则可以调用它的public成员. I suppose both the classes defined in the same project. You may freely call public static members of PersonalInfo. You may call public members of it if you have an object of type PersonalInfo (i.e. an instance of the PersonalInfo class).

类名称为PersonalInfo.它驻留在名为PersonalInfo.cs的文件中,至少我希望如此. 作为已经说过的内容的补充:如果您的一个类是从另一个类派生的(如人和员工的建议,但是我可能完全错了),则可以使用protected变量和父类的方法在子类中. The class name is PersonalInfo. It resides in a file with the name PersonalInfo.cs, at least I hope so. As an addition to what is already said: If one of your classes is derived from the other (as person and employee suggest, but I could be totally wrong on that), you could use protected variables and methods of the parent class from within the child class.

更多推荐

我如何从另一个班级召唤一个班级

本文发布于:2023-10-31 05:57:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545211.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:班级

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!