■ Dictionary 클래스 : 대소문자를 구분하지 않는 딕셔너리 사용하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

using System;

using System.Collections.Generic;

using System.Diagnostics;

using System.Windows.Forms;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : Form

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            #region 이벤트를 설정한다.

 

            this.runButton.Click += runButton_Click;

 

            #endregion

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        //////////////////////////////////////////////////////////////////////////////// Event

 

        #region 실행 버튼 클릭시 처리하기 - runButton_Click(sender, e)

 

        /// <summary>

        /// 실행 버튼 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void runButton_Click(object sender, EventArgs e)

        {

            this.caseInsensitiveTextBox.Clear();

 

            this.lowerCaseTextBox.Clear();

 

            int itemCount = int.Parse(this.itemCountTextBox.Text);

 

            Dictionary<string, string> dictionary;

            string                     key;

            string                     value;

 

            Refresh();

 

            Stopwatch watch = new Stopwatch();

 

            watch.Start();

 

            dictionary = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);

 

            for(int i = 0; i < itemCount; i++)

            {

                key   = $"Key {i.ToString()}";

                value = $"Value {i.ToString()}";

 

                if(!dictionary.ContainsKey(key))

                {

                    dictionary.Add(key, value);

                }

            }

 

            for(int i = 0; i < itemCount; i++)

            {

                key   = $"Key {i.ToString()}";

                value = $"Value {i.ToString()}";

 

                if(!dictionary.ContainsKey(key))

                {

                    dictionary.Add(key, value);

                }

            }

 

            for(int i = 0; i < itemCount; i++)

            {

                key = $"Key {i.ToString()}";

 

                if(dictionary.ContainsKey(key))

                {

                    value = dictionary[key];

                }

            }

 

            for(int i = 0; i < itemCount; i++)

            {

                key = $"Missing {i.ToString()}";

 

                if(dictionary.ContainsKey(key))

                {

                    value = dictionary[key];

                }

            }

 

            watch.Stop();

 

            this.caseInsensitiveTextBox.Text = watch.Elapsed.TotalSeconds.ToString("0.00") + " 초";

 

            this.caseInsensitiveTextBox.Refresh();

 

            watch.Reset();

 

            watch.Start();

 

            dictionary = new Dictionary<string, string>();

 

            for(int i = 0; i < itemCount; i++)

            {

                key   = $"Key {i.ToString()}";

                value = $"Value {i.ToString()}";

 

                if(!dictionary.ContainsKey(key))

                {

                    dictionary.Add(key, value);

                }

            }

 

            for(int i = 0; i < itemCount; i++)

            {

                key   = $"Key {i.ToString()}";

                value = $"Value {i.ToString()}";

 

                if(!dictionary.ContainsKey(key))

                {

                    dictionary.Add(key, value);

                }

            }

 

            for(int i = 0; i < itemCount; i++)

            {

                key = $"Key {i.ToString()}";

 

                if(dictionary.ContainsKey(key))

                {

                    value = dictionary[key];

                }

            }

 

            for(int i = 0; i < itemCount; i++)

            {

                key = $"Missing {i.ToString()}";

 

                if(dictionary.ContainsKey(key))

                {

                    value = dictionary[key];

                }

            }

 

            watch.Stop();

 

            this.lowerCaseTextBox.Text = watch.Elapsed.TotalSeconds.ToString("0.00") + " 초";

 

            this.lowerCaseTextBox.Refresh();

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요