나는 도서관 신청서를 쓰고 있는데, 나는 제목, 저자, 그리고 어떤 유형의 책 (Roman, Tidskrift, novellsamling)을 쓸 수 있어야한다.도서관 신청
이 프로그램은 제목과 저자의 두 가지 질문에 답할 때 1-3 가지 옵션이 제공되며 책 유형은 1입니다. Roman 2. Tidskrift 3. Novellsamling.
1, 2 또는 3으로 대답해야합니다. 그런 다음 VisaBöcker (영어로 된 ShowBooks) 메서드를 호출하면 1,2 또는 3의 옵션이 저장되도록 어떻게 만들 수 있습니까? 사용자가 저장하고자하는 옵션에 저장됩니다. 즉, 1을 로마자로 선택하면 "1"을 로마식 클래스에 저장하려면 어떻게해야합니까? 그러면 "Title" + "Author" + "Type (1,2,3/Roman,Tidskrift,Novellsamling)
이 표시됩니다. 예 : Pippi Långstrump by Astrid Lindgren. (Roman) <- the type of book, number 1 chosen.
지금은 책의 유형을 묻는 메시지가 표시 될 때 Roman이라는 단어를 입력 할 수 있지만 옵션으로 1,2,3 개의 문자 만 쓰면됩니다. 네가 원하는 반에 그것을 저장해야한다. 예를 들면 로마인. 대신 예약 유형을 나타내는 클래스를 사용
class Bok
{
public string Titel = "";
public string Skribent = "";
public string Typ;
class Roman : Bok
{
public Roman()
{
Typ = "Roman";
}
}
class Tidskrift : Bok
{
public Tidskrift()
{
Typ = "Tidskrift";
}
}
class Novellsamling : Bok
{
public Novellsamling()
{
Typ = "Novellsamling";
}
}
}
static List<string[]> Böcker = new List<string[]>();
static string[] bok;
public static void RegistreraBok()
{
bok = new string[3];
Console.Write("\n\tSkriv in titel: ");
bok[0] = Console.ReadLine();
Console.Write("\n\tSkriv in författare: ");
bok[1] = Console.ReadLine();
Console.Write("\n\tÄr boken en [1] Roman, [2] Tidsskrift eller [3] Novellsamling?: ");
bok[2] = Console.ReadLine();
Console.WriteLine("\n\tSparat!");
Console.ReadLine();
Böcker.Add(bok);
Console.Clear();
}
public static void VisaBöcker()
{
for (int i = 0; i < Böcker.Count; i++)
{
Console.WriteLine("\t" + Böcker[i][0] + " av " + Böcker[i][1] + "." + " (" + Böcker[i][2] + ")");
}
}
와우 매우 감사합니다. 곧 더 자세히 설명해 드리겠습니다. 완벽하게 작동하는 것처럼 보입니다. 스타일과 글쓰기/언어에 대한 '터치'를 추가 할 것입니다. 뭔가있을 경우 알려 드리겠습니다. –