主题:C#作业样本⑷-- 错在哪里?
(注:以下教程适合初学者,介绍C#。下载.NET Framework 2.0 版本到你的Windows
2000 SP4 或者Windows XP SP2。)
①打开notepad.exe
②输入以下内容( 以下01..02..只供序号参照,切记别输入):
01: using System;
02:
03: public class frmMain
04: {
05: public static void Main()
06: {
07: bool flag; int val; string strNumber; string output = "Number is
even";
08: // enter a value
09: Console.Write ("Enter a number: ");
10: Console.ReadLine ( strNumber );
11: // Convert from text to number
12: flag = int.TryParse(strNumber, out val);
13: if (flag == false)
14: {
15: Console.WriteLine("Not a number. Re-enter.");
16: return;
17: }
18: // See if odd or even
19: if (val % 2 == 1)
20: { output = "Number is odd"; }
21: // Show result
22: Console.WriteLine ( output );
23: }
24: }
③储存名档为frmMain.cs
④进入"C:\Windows\Microsoft.NET\Framework\v2.0.50727" 里头,执行csc.exe
如下:
csc.exe frmMain.cs [ 回车键 ]
这时它会显示以下讯息:
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
frmMain.cs(10,2): error CS1501: No overload for method 'ReadLine' takes
'1'arguments
c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll: (Location of
symbol
related to previous error)
……怎么这东东"(10,2): error CS1501" 第10行有问题啊?错在哪里?真伤脑筋
哦!
提示:有哪一位知道答案想告诉大家的,欢迎一同分享乐趣吧!
2000 SP4 或者Windows XP SP2。)
①打开notepad.exe
②输入以下内容( 以下01..02..只供序号参照,切记别输入):
01: using System;
02:
03: public class frmMain
04: {
05: public static void Main()
06: {
07: bool flag; int val; string strNumber; string output = "Number is
even";
08: // enter a value
09: Console.Write ("Enter a number: ");
10: Console.ReadLine ( strNumber );
11: // Convert from text to number
12: flag = int.TryParse(strNumber, out val);
13: if (flag == false)
14: {
15: Console.WriteLine("Not a number. Re-enter.");
16: return;
17: }
18: // See if odd or even
19: if (val % 2 == 1)
20: { output = "Number is odd"; }
21: // Show result
22: Console.WriteLine ( output );
23: }
24: }
③储存名档为frmMain.cs
④进入"C:\Windows\Microsoft.NET\Framework\v2.0.50727" 里头,执行csc.exe
如下:
csc.exe frmMain.cs [ 回车键 ]
这时它会显示以下讯息:
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
frmMain.cs(10,2): error CS1501: No overload for method 'ReadLine' takes
'1'arguments
c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll: (Location of
symbol
related to previous error)
……怎么这东东"(10,2): error CS1501" 第10行有问题啊?错在哪里?真伤脑筋
哦!
提示:有哪一位知道答案想告诉大家的,欢迎一同分享乐趣吧!