Cравнение двух моделей - C#
Формулировка задачи:
Листинг программы
- internal class StructuresAlone
- {
- public string Fio { set; get; }
- public int Pol { set; get; }
- public DateTime DateRo { set; get; }
- public DateTime DateSm { set; get; }
- public string Country { set; get; }
- public string Street { set; get; }
- public string Phone { set; get; }
- public string PlaceWork { set; get; }
- public string SemPol { set; get; }
- }
Листинг программы
- private StructuresAlone _alone;
- private void AloneLoad()
- {
- _alone = new StructuresAlone();
- ...заполнение....
- }
- private void tabControl1_Deselecting(object sender, TabControlCancelEventArgs e){
- var structuresAlone = new StructuresAlone
- {
- Country = comboBox2.Text,
- DateRo = dateTimePicker1.Value,
- DateSm = dateTimePicker2.Value,
- Fio = textBox1.Text,
- Phone = textBox3.Text,
- Street = textBox2.Text,
- SemPol = comboBox3.Text,
- PlaceWork = textBox12.Text
- };
- if (radioButton1.Checked)
- structuresAlone.Pol = 1;
- if (!structuresAlone.Equals(_alone))
- {
- if (AloneEdit())
- {
- MessageBox.Show(@"Данные успешно изменены.", @"Успешно", MessageBoxButtons.OK,
- MessageBoxIcon.Information);
- }
- }
- }
Листинг программы
- if (!structuresAlone.Equals(_alone))
Решение задачи: «Cравнение двух моделей»
textual
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication41 {
- class Program {
- static void Main(string[] args) {
- TestObj t1 = new TestObj { X = 10, Y = 20 };
- TestObj t2 = new TestObj { X = 10, Y = 21 };
- Console.WriteLine(t1 == t2);
- Console.ReadLine();
- }
- }
- public class TestObj : IEquatable<TestObj> {
- public int X { get; set; }
- public int Y { get; set; }
- public bool Equals(TestObj other) {
- if (other == null) {
- return false;
- }
- return X == other.X && Y == other.Y;
- }
- public override string ToString() {
- return string.Format("X={0}, Y={1}", X, Y);
- }
- public override int GetHashCode() {
- return (X * Y) ^ 127;
- }
- public override bool Equals(object obj) {
- return Equals(obj as TestObj);
- }
- public static bool operator ==(TestObj t1, TestObj t2) {
- if (object.ReferenceEquals(t1, t2)) {
- return true;
- }
- if ((object)t1 == null || (object)t2 == null) {
- return false;
- }
- return t1.X == t2.X && t1.Y == t2.Y;
- }
- public static bool operator !=(TestObj t1, TestObj t2) {
- return !(t1 == t2);
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д