C#菜鸟级问题,望大虾指教!!

swx002 2010-09-13 10:48:01
以下是偶写的代码,题目是:编写一个简单的具有输入输出功能的控制台程序:通过控制台输入/输出方法Console.ReadLine()/Console.WriteLine()输入某人的信息,包括:name,title,phone,email,affiliation,并按照下属格式输出:
<name> <title>
<affiliation>
Email:< email> Phone:<phone>
说明:<>是指变量的值,没有<>的为字符串

我想用结构体,但调试时老是提示无法转换类型,还望大虾指教指教,本人刚学C#!!



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace student_information
{
class information
{
struct student
{
public string strName;
public string strTitle;
public sbyte sbPhone;
public string strEmail;
public string strAffiliation;
}
student stu;
static void Main(string[] args)
{
information S = new information();
Console.WriteLine("Please enter your information:Name,Title,Phone,Email,Affiliation.");
S.stu.strName = Console.Read();
S.stu.strTitle = Console.Read();
S.stu.sbPhone = Console.Read();
S.stu.strEmail = Console.Read();
S.stu.strAffiliation = Console.Read();
Console.WriteLine("您的信息为:\n{0}\n{1}\n{2}\n{3}\n{4}\n欢迎使用C#!", S.stu.strName, S.stu.strTitle, S.stu.sbPhone, S.stu.strEmail, S.stu.strAffiliation);
}
}
}
...全文
93 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
swx002 2010-09-15
  • 打赏
  • 举报
回复
谢谢各位!!
KeepSayingNo 2010-09-14
  • 打赏
  • 举报
回复
我帮你重写了下,你看看

using System;
using System.Collections.Generic;
using System.Text;

using ConsoleApp;

namespace ConsoleApp
{
class Program
{
struct Student
{

public string strName, strTitle, strPhone, strEmail, strAffiliation;
}

Student stu;

static void Main(string[] args)
{
Console.WriteLine("Please enter your information:Name,Title,Phone,Email,Affiliation.");

Program prograim=new Program();
prograim.stu.strName=Console.ReadLine();
prograim.stu.strTitle=Console.ReadLine();
prograim.stu.strPhone=Console.ReadLine();
prograim.stu.strEmail=Console.ReadLine();
prograim.stu.strAffiliation=Console.ReadLine();

Console.WriteLine("您的信息为:\n{0}\n{1}\n{2}\n{3}\n{4}\n欢迎使用C#!", prograim.stu.strName, prograim.stu.strTitle, prograim.stu.strPhone, prograim.stu.strEmail, prograim.stu.strAffiliation);

Console.WriteLine("hehe");

}
}
}



需要注意的是以后类名最好每个单词的首字母大写。
yifeng4592 2010-09-14
  • 打赏
  • 举报
回复
受用。学习学习!
myhope88 2010-09-13
  • 打赏
  • 举报
回复
对啊,那个sbPhone应该是用string类型的吧
yangquanlaohou 2010-09-13
  • 打赏
  • 举报
回复
挣点可用分。嘻嘻嘻!!!
dqsweet 2010-09-13
  • 打赏
  • 举报
回复
sbPhone 也用string 吧

110,500

社区成员

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

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

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