无法将类型“string”隐式转换为“int”

maimiaoxiaobing 2011-03-20 04:27:32
namespace student
{
class student
{
public string name;
public string num;
public int sc;
public int seng;
public int smath;
public int avg;
}
class Program
{
static void Main(string[] args)
{
}
public static void input(params student[] s)
{
for (int i = 0; i < s.Length; i++)
{
s[i] = new student();
Console.Write("姓名:");
s[i].name = Console.ReadLine();
Console.Write("学号:");
s[i].num = Console.ReadLine();
Console.Write("c++成绩:");
s[i].sc = Convert.ToInt32(objReader[""]);
Console.Write("英语成绩:");
s[i].seng = Convert.ToInt32(objReader[""]);
Console.Write("数学成绩:");
s[i].smath = Convert.ToInt32(objReader[""]);

}

}

}
...全文
385 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
maimiaoxiaobing 2011-03-20
  • 打赏
  • 举报
回复
s[i].sc = int.Parse(Console.ReadLine());
解决了,谢谢~
maimiaoxiaobing 2011-03-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xinkeasw 的回复:]
将String 转换成int
string s="123"; 
int i=int.Parse(s);

你是想读取输入的数字吧
控制台不熟
好象可以这么写
s[i].sc = int.Parse(Console.ReadLine());
[/Quote]
恩,嘿嘿,刚刚开始学还不太懂。我试试啊~
maimiaoxiaobing 2011-03-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 winola 的回复:]
晕死,你先把student类先单独提取出来。
然后你在调用的时候呀,你参数里面那些值是怎么给的
还有objReader这个怎么来的
[/Quote]我这个是在网上找的类似的改的,本来是想粘自己写的那个结果粘成改后的了。呵呵
本来是这样的:Console.Write("C++成绩:");
s[i].score_cpp = int.Parse(Console.ReadLine());
tsjit 2011-03-20
  • 打赏
  • 举报
回复
s[i].num = Console.ReadLine();
Console.Write("c++成绩:");
s[i].sc = int.Parse(s[i].num;
软刺刺猬 2011-03-20
  • 打赏
  • 举报
回复
将String 转换成int
string s="123"; 
int i=int.Parse(s);

你是想读取输入的数字吧
控制台不熟
好象可以这么写
s[i].sc = int.Parse(Console.ReadLine());
phil999 2011-03-20
  • 打赏
  • 举报
回复
好歹说说错误在第几行,你当我是编译器
Winola 2011-03-20
  • 打赏
  • 举报
回复
晕死,你先把student类先单独提取出来。
然后你在调用的时候呀,你参数里面那些值是怎么给的
还有objReader这个怎么来的

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧