January 20

Пост 20.01.2026

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace MovieCatalog

{

public partial class Form1 : Form

{

List<Movie> movies = new List<Movie>();

public Form1()

{

InitializeComponent();

comboBoxSort.Items.AddRange(new string[]

{

"По названию",

"По году",

"По рейтингу"

});

comboBoxSort.SelectedIndex = 0;

dataGridView1.AutoGenerateColumns = true;

}

private void Form1_Load(object sender, EventArgs e)

{

movies.Add(new Movie { Title = "Inception", Year = 2010, Genre = "Sci-Fi", Rating = 8.8 });

movies.Add(new Movie { Title = "Interstellar", Year = 2014, Genre = "Sci-Fi", Rating = 8.6 });

movies.Add(new Movie { Title = "Gladiator", Year = 2000, Genre = "Drama", Rating = 8.5 });

UpdateGrid();

}

private void UpdateGrid()

{

dataGridView1.DataSource = null;

dataGridView1.DataSource = movies;

}

private void textBoxSearch_TextChanged(object sender, EventArgs e)

{

var filtered = movies

.Where(m => m.Title.ToLower().Contains(textBoxSearch.Text.ToLower()))

.ToList();

dataGridView1.DataSource = filtered;

}

private void comboBoxSort_SelectedIndexChanged(object sender, EventArgs e)

{

switch (comboBoxSort.SelectedItem.ToString())

{

case "По названию":

movies = movies.OrderBy(m => m.Title).ToList();

break;

case "По году":

movies = movies.OrderBy(m => m.Year).ToList();

break;

case "По рейтингу":

movies = movies.OrderByDescending(m => m.Rating).ToList();

break;

}

UpdateGrid();

}

private void buttonAdd_Click(object sender, EventArgs e)

{

movies.Add(new Movie

{

Title = "Новый фильм",

Year = 2024,

Genre = "Жанр",

Rating = 7.0

});

UpdateGrid();

}

private void buttonExport_Click(object sender, EventArgs e)

{

using (StreamWriter sw = new StreamWriter("movies.csv", false, Encoding.UTF8))

{

sw.WriteLine("Название;Год;Жанр;Рейтинг");

foreach (var m in movies)

{

sw.WriteLine(quot;{m.Title};{m.Year};{m.Genre};{m.Rating}");

}

}

MessageBox.Show("Экспорт в CSV выполнен");

}

}

}

Movie.cs

namespace MovieCatalog

{

public class Movie

{

public string Title { get; set; }

public int Year { get; set; }

public string Genre { get; set; }

public double Rating { get; set; }

}

}

Form1.Designer.cs (интерфейс)

Добавь на форму вручную (через дизайнер):

Элементы:

  • DataGridView → dataGridView1
  • TextBox → textBoxSearch
  • ComboBox → comboBoxSort
  • Button → buttonAdd
  • Button → buttonExport

Подписи:

  • textBoxSearch — поиск
  • comboBoxSort — сортировка
  • buttonAdd — “Добавить”
  • buttonExport — “Экспорт CSV”

(Расположение любое — логика не зависит от координат