Я новичок в C# и у меня проблема с перегрузкой списка list,при попытке заполнить список данными из файла появляется ошибка перегрузки списка List<Books>
.
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using Курсовая_негра;
namespace Курсовая_негра
{
internal class Books
{
string s;
string author;
int zalog_cost;
int cost_prokat;
string jenre;
public string S { get { return s; } }
public string Author { get { return author; } }
public int Zalog_cost { get { return zalog_cost; } }
public int CostProkat { get { return cost_prokat; } }
public string Jenre { get { return jenre; } }
public Books(string S, string Author, int Zalog_cost, int CostProkat, string Jenre)
{
s = S;
author = Author;
zalog_cost = Zalog_cost;
cost_prokat = CostProkat;
jenre = Jenre;
}
public void printBooks()
{
Console.WriteLine("Название: {0};\nАвтор: {1};\nСтоимость книги: {2}$;\nСтоимость проката книги: {3}$;\nЖанр: {4};", s, author, zalog_cost, cost_prokat, jenre);
}
}
}
class BooksFile
{
List<Books> m;
int l;
public int L { get { return l; } }
public BooksFile()
{
m = new List<Books>();
string S = "";
string Author = "";
int Zalog_cost = 0;
int CostProkat = 0;
string Jenre = "";
try
{
StreamReader sr = new StreamReader("C:\\Users\\Artem\\source\\repos\\негры\\негры\\Books.txt");
while (true)
{
string line = sr.ReadLine();
if (line == null)
break;
if (Int32.TryParse(line, out CostProkat))
{
S = sr.ReadLine();
Author = sr.ReadLine();
Zalog_cost = int.Parse(sr.ReadLine());
CostProkat = int.Parse(sr.ReadLine());
Jenre = sr.ReadLine();
m.AddRange(S,Author,Zalog_cost,CostProkat,Jenre);
}
else
Console.WriteLine($"Некорректный ввод ");
}
sr.Close();
}
catch
{
Console.WriteLine("Нет файла! ");
}
l=m.Count;
}
public void BooksUses()
{
Console.WriteLine();
Console.WriteLine("Книги: ");
for (int i = 0; i < l; i++)
m[i].printBooks();
Console.WriteLine();
}
}
Ошибка:
Ошибка CS1501 Ни одна из перегрузок метода "AddRange" не принимает 5 аргументов.