Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 1125|回复: 5
打印 上一主题 下一主题

关于C# 的问题 , 第一天学习~

[复制链接]

9

主题

0

好友

240

积分

支柱会员

Rank: 4Rank: 4Rank: 4Rank: 4

跳转到指定楼层
1#
发表于 2011-7-10 12:31 PM |只看该作者 |正序浏览
  1. using System;
  2. using System.Windows.Forms;

  3. class Tutorial1{
  4.        
  5.         static void Main(string[]args){
  6.                 //Console.WriteLine("Hello ");
  7.                 //MessageBox.Show("Hello~","Message");
  8.                
  9.                 int num1=0,num2=0,total=0;
  10.                
  11.                 Console.WriteLine("Please Enter the first integer :");
  12.                 num1=Int32.Parse(Console.ReadLine());
  13.                
  14.                 Console.WriteLine("Please Enter the second integer :");
  15.                 num2=Int32.Parse(Console.ReadLine());
  16.                
  17.                 total=num1+num2;
  18.                
  19.                 Console.WriteLine("The total of {0} and {0} is {0}",num1,num2,total);
  20.        
  21.         }
  22. }
复制代码
Application Output :

Please Enter the first integer :

Unhandled Exception: System.ArgumentNullException: Argument cannot be null.
Parameter name: s
  at System.Int32.Parse (System.String s) [0x00000] in <filename unknown>:0
  at Tutorial1.Main (System.String[] args) [0x00000] in <filename unknown>:0
The application was terminated by a signal: SIGHUP

COmpiler : MonoDevelop
OS platform :  ubuntu 10.10 ~~

小第第一天学C# ~这里就stuck 了。。可是 microsoft visual basic 2010 , 可以compiler ~没问题。。。小第 google 好多次了, 有些说 bug ~~
希望这里的朋友指点下。。




收藏收藏0

15

主题

0

好友

118

积分

高级会员

Rank: 3Rank: 3Rank: 3

6#
发表于 2011-7-12 07:42 AM |只看该作者
我建议你使用单步调试,别人帮你说出来,你日后再犯也未必真懂问题发在哪~


回复

使用道具 举报

31

主题

0

好友

1228

积分

黄金长老

Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8

5#
发表于 2011-7-11 09:57 AM |只看该作者
我随便 google 了一下下,楼主你看看是不是这个问题。
http://anxma.com/index.php/2009/08/06/mono-console/


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

4#
发表于 2011-7-10 07:22 PM |只看该作者
我也猜到了,网上看到的是bug ..~~没有什么解决方案 ~~
请问照你的经验, 这个问题可以解决吗?还是有什么好的compiler 介绍?

monodevelop , 如果只是Messagebox.Show(); 就可以compile 还有显示 。。
可是如果是scan input 就不可以。。

monodevelop是我从 ubuntu software centre 下载下来的 。。如果有text editor 去编写 我比较不喜欢。。
pang1989 发表于 2011-7-10 05:38 PM



我没學 C# 所以不知道甚么情况下可以解决,我之所以會說是因為 Console 方面的 system("pause") 等在 terminal 上也是無法编译,所以 pause 的問題必須改成循环 getchar 來替代。

對於 Int32.parse 的参數好像必須是 string,但看您一樓的運行结果是:
  1. Application Output :

  2. Please Enter the first integer :

  3. Unhandled Exception: System.ArgumentNullException: Argument cannot be null.
  4. Parameter name: s
  5.   at System.Int32.Parse (System.String s) [0x00000] in <filename unknown>:0
  6.   at Tutorial1.Main (System.String[] args) [0x00000] in <filename unknown>:0
  7. The application was terminated by a signal: SIGHUP
复制代码


first integer 没輸入直接按 enter 的情况下正常應該就會出現錯誤吧,不然您加個判断 readline 是否為空看看


回复

使用道具 举报

9

主题

0

好友

240

积分

支柱会员

Rank: 4Rank: 4Rank: 4Rank: 4

3#
发表于 2011-7-10 05:38 PM |只看该作者
[quote]樓主是用 linux 系统,所以 terminal 与 console 的 system library 會出現一些不兼容的情况
Super-Tomato 发表于 2011-7-10 02:50 PM [/quote

我也猜到了,网上看到的是bug ..~~没有什么解决方案 ~~
请问照你的经验, 这个问题可以解决吗?还是有什么好的compiler 介绍?

monodevelop , 如果只是Messagebox.Show(); 就可以compile 还有显示 。。
可是如果是scan input 就不可以。。

monodevelop是我从 ubuntu software centre 下载下来的 。。如果有text editor 去编写 我比较不喜欢。。


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

2#
发表于 2011-7-10 02:50 PM |只看该作者
Application Output :

Please Enter the first integer :

Unhandled Exception: System.ArgumentNull ...
pang1989 发表于 2011-7-10 12:31 PM



樓主是用 linux 系统,所以 terminal 与 console 的 system library 會出現一些不兼容的情况


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-29 03:30 AM , Processed in 0.102098 second(s), 29 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部