帮助C#代码不编译 [英] Help C# code not compiling

查看:139
本文介绍了帮助C#代码不编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,为什么不会这两个(A和B)编译?编译时,我不断收到以下错误:无法找到类型或命名空间名称''表单'



A)

  public   class  MyApp 
{
< span class =code-keyword> public static void Main()
{
System.Console.WriteLine( Hello);
myNamespace .Console.myMethod();
}
}



B)

 使用系统; 
public class MyApp
{
public static void main()
{
System.Console.WriteLine( Hello ) ;
myNamespace.Console.myMethod();
}
}

解决方案

首先,请记住这种语言区分大小写(参见B, 主要)。



您没有显示与该问题相关的代码。首先,从未提及表单,但显然它在您的代码中的某处。提到了名称myMethod,但是没有显示定义它的代码(如果有的话)。



你提问的整个方法完全没用;如果你自己没有看到,我不知道该怎么做。通常,注意错误信息就足够了,尤其是报告中的代码行。







只需一个注释:实际上,Forms UI和控制台可以一起使用。应用程序类型应为控制台。这种类型没有说你不能使用WPF应用程序的形式,它只是说将显示控制台,所以其他任何东西都会被显示出来。



-SA


你真的需要在C#上获取一本初学者书并完成它。



替换以下行:

 myNamespace.Console.myMethod(); 



with

 myMethod(); 





你不需要指定命名空间,除非你调用的类/方法实际上是另一个名称空间,而不是你调用的名称空间。


hey guys , why won''t these two ( A and B) compile?? when compiled i keep getting this following error: "The type or namespace name ''Form'' could not be found"

A)

public class MyApp
{
public static void Main()
{
System.Console.WriteLine("Hello");
myNamespace.Console.myMethod();
}
}


B)

using System;
public class MyApp
{
public static void main()
{
System.Console.WriteLine("Hello");
myNamespace.Console.myMethod();
}
}

解决方案

First of all, remember that this language is case-sensitive (see B, "main").

You did not show the code relevant to the question. First, "Form" is never mentioned, but apparently it is there somewhere in your code. The name "myMethod" is mentioned, but the code where it is defined, if any, is not shown.

Your whole approach to asking question is totally useless; if you don''t see it yourself, I don''t know what to do. Usually, it''s enough to pay attention for error information, especially to the line of code reported in it.

[EDIT]

Just one note: actually, Forms UI and console can be used together. The application type should be "Console". This type does not say "you cannot use Forms of WPF application", it simply says "console will be shown", so anything else will be shown, too.

—SA


You REALLY need to pickup a beginners book on C# and work through it.

Replace the line that says:

myNamespace.Console.myMethod();


with

myMethod();



You don''t need to specify a namespace unless the class/method you''re calling is actually in another namespace other than the one your calling from.


这篇关于帮助C#代码不编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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