它没有方法c#的定义 [英] it does not have a definition for the method c#

查看:90
本文介绍了它没有方法c#的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学校上课时有方法.我在一个学生班级里诱使那个班级,并从这个班级中调用该方法.它以前曾起作用,但现在不起作用.相反,它说:它在最初来自该方法的学校课堂中没有该方法的定义.请您帮我一个忙吗?是与引用或.dll或类似的东西有关吗?

Im having a method in a school class. and Im intanciating that class in a student class and calling that method from this class. It worked before but not working now. instead it says" it does not have a definition for the method in the school class where the method is originally from. Could you help me out please? is it something to do with the reference or .dll or something like that

推荐答案

这将取决于很多事情:可能是其中任何一个.
首先,我假设学校班级和学生班级都在同一项目中?如果不是,那么这是一个相对简单的问题.

您为什么要实例化一所学校?从逻辑上说,一所学校将独立于特定学生而存在,因为它将有很多学生,而不是有很多学校的学生.

实例化学校时,大概是在使用实例访问方法(或者您不会提到它):
It''s going to depend on quite a few things: it could be any one of them.
First, I assume that the school class and the student class are both in the same project? If not, then it is a relatively simple problem.

Why would you instantiate a school from a student? A school would logically exist independently of the particular student, because it would have many students - rather than a student having many schools.

When you instantiate the school, you are presumably using the instance to access the method (or you wouldn''t have mentioned it):
School s = new School ();
Console.WriteLine(s.GetName());

这里要检查两件事,两者都与方法定义有关:
1)该方法是否声明为public?如果不是,并且学生不是从School派生的,那么您将无法从外部访问它.
2)该方法是否声明为static?如果是,那么您将无法从实例访问它,而必须使用类名:

There are two things to check here, both related to the method definition:
1) Is the method declared as public? If it isn''t, and Student isn''t derived from School, then you cannot access it from outside.
2) Is the method declared as static? If it is, then you can''t access it from the instance, you have to use the class name instead:

Console.WriteLine(School.GetName());


好像存在dll引用-该类似乎正在被初始化.
确保您的方法具有适当的访问修饰符.
Looks like the dll reference is there - the class seems to be getting intiantiated.
Make sure your method had the appropriate access modifier.


这篇关于它没有方法c#的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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