Alles klar, ich habe einen Code für eine Bibliothek erstellt, es ist ziemlich einfach, aber ich muss nach Schlüsselwörtern suchen, um den Titel eines Buches zu finden. Ich habe eine Bücherliste mit den Titeln Titel, Autor, ISBN und Genre erstellt. Ich brauche nur jemanden, der mir in die richtige Richtung zeigt, wonach ich suchen soll. Ich füge den Teilcode an, um dir die Liste zu zeigen, die ich erstellt habe! Ich muss nur wissen, was ich in meine Methode Search eingeben soll. Vielen Dank, dass SieC# suche eine Liste
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CodersVilleLibrary
{
public class Books
{
public static List<Books> _books = new List<Books>();
public string Title
{ get; set; }
public string Author
{ get; set; }
public string ISBN
{ get; set; }
public string Genre
{ get; set; }
static Books()
{
_books.Add(new Books()
{
Title = "Lord of the Rings",
Author = "J.R.R. Tolkein",
ISBN = "0395595118",
Genre = "Adventure"
});
_books.Add(new Books()
{
Title = "Lord of the Flies",
Author = "William Golding",
ISBN = "0571056865",
Genre = "Sci-Fi"
});
_books.Add(new Books()
{
Title = "Hunger Games",
Author = "Suzanne Collins",
ISBN = "9780439023528",
Genre = "Sci-Fi"
});
}
}
}
Benutzer Klasse
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CodersVilleLibrary
{
public class Users
{
private static List<Users> _users = new List<Users>();
public string Username
{ get; set; }
public string Password
{ get; set; }
public Address Address
{ get; set; }
public static Users Authorize()
{
string username = null;
string password = null;
Console.WriteLine("Enter Your Username: ");
username = Console.ReadLine();
Console.WriteLine("Enter Your Password: ");
password = Console.ReadLine();
return _users.Where(u => u.Username == username && u.Password == password).FirstOrDefault();
}
static Users()
{
_users.Add(new Users()
{
Username = "FDalton",
Password = "Kelton",
Address = new Address
{
City = "Mascoutah",
State = "IL",
StreetAddress1 = " 834 Locust Dr.",
ZIP = "62258"
}
});
_users.Add(new Users()
{
Username = "Bnotz",
Password = "Ben",
Address = new Address
{
City = "O'Fallon",
State = "IL",
StreetAddress1 = "700 Old School Road",
ZIP = "62269"
}
});
}
internal void CreateSession()
{
int selection = GetAction();
if (selection != 3)
{
Books bks = SearchBooks();
switch (selection)
{
// Search
case 1:
break;
// ViewAll
case 2:
break;
}
}
}
private Books SearchBooks()
{
var byTitle = Books.Where(while
}
int GetAction()
{
int choice = -1;
bool isValid = true;
string input = null;
do
{
if(!isValid)
{
Console.WriteLine("Invalid Input! Try Again.");
}
Console.WriteLine("");
Console.WriteLine("Welcome to Codesville Library System");
Console.WriteLine("Please Select an action");
Console.WriteLine("___________________________");
Console.WriteLine(" 1.) Search for a Book");
Console.WriteLine(" 2.) See all books in the system");
Console.WriteLine(" 3.) Exit");
Console.WriteLine("");
input = Console.ReadLine();
}
while ((!(isValid = Int32.TryParse(input, out choice))) ||
choice < 1 ||
choice > 3);
return choice;
}
}
}
Sie sagten, Sie möchten nach Titel suchen? in die richtige Richtung für was zu suchen? – Peru
Wo ist Ihre Suchmethode? – chomba
Scheint, als ob Ihre Klasse "Book" sein sollte, nicht "Books" und "_books" gehört nicht zu dieser Klasse. (BTW: ein öffentliches Feld wie '_books' ist kein C# Weg) – Eser