728x90
반응형

[예제1]

using System.Collections.Generic;
using static System.Console;
namespace ConsoleApp1
{
    class Aaa
    {
        // List<int> li = new List<int>();
        List<Bbb> li = new List<Bbb>();
        public void f1(string s1, string s2)
        {
            Bbb t = new Bbb();
            t.f2(this, s1, s2);
        }
        public void showData()
        {
            foreach (var data in li)
            {
                WriteLine(data.getItem() + " " + data.getValue());
            }
        }
        public void showData(string item)
        {
            foreach (var data in li)
            {
                if (data.getItem() == item)
                {
                    WriteLine(data.getValue());
                }
            }
        }
        class Bbb
        {
            private string item;
            public string getItem() { return item; }
            private string value;
            public string getValue() { return value; }
            public void f2(Aaa thiscf, string item, string value)
            {
                this.item = item;
                this.value = value;
                WriteLine(thiscf.li.Count);
                bool found = false;
                for (int i = 0; i < thiscf.li.Count; i++)
                {
                    if (thiscf.li[i].item == item)
                    {
                        thiscf.li[i] = this;
                        found = true;
                        break;
                    }
                }
                if (found == false)
                {
                    thiscf.li.Add(this);
                }
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Aaa aaa = new Aaa();
            WriteLine("============Version===========");
            aaa.f1("Version", "5.0");
            WriteLine("==============Size============");
            aaa.f1("Size", "5000");
            WriteLine("=============Price============");
            aaa.f1("Price", "400000");
            WriteLine("==============Date============");
            aaa.f1("Date", "12월20일");
            //
            WriteLine("============Size==============");
            aaa.f1("Size", "8000");
            WriteLine("=============Version==========");
            aaa.f1("Version", "7.0");
            WriteLine("============showData==========");
            aaa.showData();
            WriteLine("=============Size====+========");
            aaa.showData("Size");
        }
    }
}

728x90
반응형

'Education > Edu | .net' 카테고리의 다른 글

# 26.3) [C#] 문법8 (Property)  (0) 2021.02.19
# 26.2) [C#] 문법7 (interface)  (0) 2021.02.19
# 25.2) [C#] 문법5 (Class)  (0) 2021.02.18
# 25.1) [C#] 문법4  (0) 2021.02.18
# 24.2) [C#] 문법3  (0) 2021.02.17

+ Recent posts