-1
私の質問です:新しいオブジェクトを作成した後にコンストラクタのプロパティにアクセスできる方法はありますか?C#リストから特定のコンストラクタのプロパティを持つクラスオブジェクトを削除する
私はこのクラスを作成しました:
class Book
{
private string Title { get; set; }
private string Author { get; set; }
private string ISBN { get; set; }
public bool Available { get; set; }
public Book(string title, string author, string isbn)
{
this.Title = title;
this.Author = author;
this.ISBN = isbn;
}
}
は、それから私は、次のように新しいオブジェクトを作成します。
Book myBook = new Book("Strategic Management", "John Doe", "1234567");
は、どのように私は上記の目的からタイトルを抽出することができますか?ほとんどの場合、唯一のsetter
方法は、プロパティにカプセル化され、事前に
public void RemoveLoan(Book oldLoan)
{
var item = Loans.SingleOrDefault(x => x.Book.Title == oldLoan.Title);
if (item != null)
{
Loans.Remove(item);
}
}
おかげ
なぜそれらのプロパティはプライベートですか?プライベートなのでアクセスできません。 –
プロパティを 'public'にします。このようなものを常に読みやすくすることができます。 'public string Title {get;プライベートセット; } ' – juharr
これは学校の割り当てですが、私は要件にちょうど従っています。 – Igor