21 Nisan 2018

C# Indexer Örneği

using System;
using System.Collections.Generic;

namespace CSharpIntermediate
{

    public class HttpCookie
    {
        private readonly Dictionary<string, string> dictionary;
        public HttpCookie()
        {
            dictionary = new Dictionary<string, string>();
        }
        public string this[string key]
        {
            get
            {
                return dictionary[key];
            }
            set
            {
                dictionary[key] = value;
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var httpCookie = new HttpCookie();
            httpCookie["username"] = "admin";
            Console.WriteLine(httpCookie["username"]);
        }
    }
}