我如何从另一个班级召唤一个班级-C# [英] How do i call one class from another - C#

查看:378
本文介绍了我如何从另一个班级召唤一个班级-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.


我想这两个类都在同一个项目中定义.
您可以自由调用publicpublic 静态成员.
如果具有类型为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.


这篇关于我如何从另一个班级召唤一个班级-C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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