如何在C#中使用字符串创建结构数组

时间:2018-09-23 04:42:14

标签: c# arrays

注意 这是一项作业,不是寻找直接答案,而是指导,所以我可以找出答案。...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Convert;

namespace OnYourOwnCalendar
{

struct Appointment
{
    public string title;
    public string description;
    public string date;
    public string startTime;
    public string endTime;
    public string who;
}
class Program
{
    static void Main(string[] args)
    {
        Appointment app;
        string myTitle;
        string myDescription;
        string myDate;
        string theStartTime;
        string theEndTime;
        string theWho;
        WriteLine("Welcome to your appointment book");
        for (int i = 1; i < 6; i++)
        {

            Write("Please tell me your first appointments title: ");
            myTitle = ReadLine();
            Write("Please tell me a brief description of your appointment: ");
            myDescription = ReadLine();
            Write("Please tell me the date of your appointment: ");
            myDate = ReadLine();
            Write("Please tell me the time of your appointment: ");
            theStartTime = ReadLine();
            Write("Please tell me the time your appointment ends: ");
            theEndTime = ReadLine();
            Write("Please tell me who your appointment is with: ");
            theWho = ReadLine();
            app.title = myTitle;
            app.description = myDescription;
            app.date = myDate;
            app.startTime = theStartTime;
            app.endTime = theEndTime;
            app.who = theWho;
            WriteLine($"Your appointment is:\nTitle:{app.title}\nDescription:{app.description}\nDate:{app.date}\nStart Time:{app.startTime}\nEnding Time:{app.endTime}\nWho is Required:{app.who}");
            Write("================Press Enter to Continue================");
            ReadKey();
        }
        /*foreach (string App in appArray)
        {
            WriteLine($"Your appointment is:\nTitle:{app.title}\nDescription:{app.description}\nDate:{app.date}\nStart Time:{app.startTime}\nEnding Time:{app.endTime}\nWho is Required:{app.who}");
            ReadKey();
            Write("================Press Enter to Continue================")
        }*/
    }
}

此代码可用于所有密集型目的,问题是我需要创建一个结构数组,然后重新输入所有输入的信息。 当我去创建书中显示的数组元素时,使用:

Appointment[] app = new Appointment[6];

我开始遇到各种各样的错误,我尝试了所有可能想到的方法,对一本教科书的1980年代立体声手册进行了1000多次扫描,不幸的是,我的教授在回答问题上毫无用处问题。 因此,我认为我已经看到了所有可能的错误,从无法将类型string []隐式转换为string,到不包含“”的定义,并且没有可访问的扩展方法等等……我在这里不明白什么?我该如何进行这项工作?

0 个答案:

没有答案