Несовместимость по доступности: доступность типа поля "System.Collections.ObjectModel.Collection" ниже доступно - C#
Формулировка задачи:
Добрый вечер....У меня пишет ошибку Несовместимость по доступности: доступность типа поля "System.Collections.ObjectModel.Collection<WindowsFormsApplication1.Form1.Record>" ниже доступности поля "WindowsFormsApplication1.Form1.records" d:\Users\алекс\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 16 35 WindowsFormsApplication2
подкажите как решить пожалуйсто
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Collections.ObjectModel;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Collection<Record> records = new Collection<Record>(); //ошибку выдает в это строке подчеркивая records
- StreamReader reader;
- StreamWriter writer;
- class Record
- {
- public String Name, date, za4;
- }
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- LoadFromFile();
- }
- private void SaveToFile()
- {
- writer = new StreamWriter("data.txt");
- for ( int i = 0; i< records.Count; i++)
- {
- writer.WriteLine(records[i].Name);
- writer.WriteLine(records[i].date);
- writer.WriteLine(records[i].za4);
- }
- writer.Close();
- }
- private void LoadFromFile()
- {
- Record record;
- reader = new StreamReader("data.txt");
- while (!reader.EndOfStream)
- {
- record = new Record();
- record.Name = reader.ReadLine();
- record.date = reader.ReadLine();
- record.za4 = reader.ReadLine();
- reader.ReadLine();
- records.Add(record);
- }
- reader.Close();
- }
- private void Form1_Shown(object sender, EventArgs e)
- {
- FillListBox();
- }
- private void FillListBox()
- {
- listBox1.Items.Clear();
- for (int i = 0 ; i<records.Count; i++)
- {
- listBox1.Items.Add(records[i].Name + ' ' + records[i].date + ' ' + records[i].za4);
- }
- listBox1.Items.Add("(new)");
- }
- private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (listBox1.SelectedIndex < 0 ) return;
- if (listBox1.SelectedIndex < records.Count)
- {
- textBox1.Text = records[listBox1.SelectedIndex].Name;
- textBox1.Text = records[listBox1.SelectedIndex].date;
- textBox1.Text = records[listBox1.SelectedIndex].za4;
- }
- else
- {
- textBox1.Text= " ";
- textBox2.Text= " ";
- textBox3.Text= " ";
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- if (listBox1.SelectedIndex< records.Count)
- records.Remove(records[listBox1.SelectedIndex]);
- SaveToFile();
- FillListBox();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (listBox1.SelectedIndex == listBox1.Items.Count-1)
- {
- Record record = new Record();
- record.Name = textBox1.Text;
- record.date = textBox1.Text;
- record.za4 = textBox1.Text;
- }
- SaveToFile();
- FillListBox();
- }
- }
- }
Решение задачи: «Несовместимость по доступности: доступность типа поля "System.Collections.ObjectModel.Collection" ниже доступно»
textual
Листинг программы
- public class Record
- {
- public String Name, date, za4;
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д