> For the complete documentation index, see [llms.txt](https://docs.dot-net.uz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dot-net.uz/c-.net/basic/yuqori-daraja/toplamlar/dictionary.md).

# Dictionary

**Dictionary** "TKey, TValue" shablonidagi klass bo'lib, **System.Collection.Generics** namespace sida joylashgan. **Dictionary** kalitlar va qiymatlar to'plami bo'lib, boshqa to'plamlar kabi kalit/qiymat ko'rinishida element qabul qiladi. **Hashtable** dan farqi, **Dictionary** da qidirish tizimi tezroq

```csharp
    using System.Collections.Generic;
```

{% hint style="info" %}
**MUHIM QOIDALAR!**

• Kalitlar bir xil bo'lmasligi kerak

• Kalit null qiymat qabul qilmaydi
{% endhint %}

## Misol:

```csharp
     Dictionary<string, string> Mdic = new Dictionary<string, string>();

            Mdic.Add("1", ".NET");   //1 juftliklar soni
            Mdic.Add("2", "C#");     //2
            Mdic.Add("3", "Asp.NET");//3
            Mdic.Add("4", "LINQ");   //4

            Console.WriteLine($"juftliklar soni : {Mdic.Count}");

            foreach (var item in Mdic)
            {
                Console.WriteLine($"Kalit = {item.Key}  Qiymat = {item.Value}");
            }
```

![](/files/-MePZ40utSEj7lZTEoc7)

```csharp
    Dictionary<string, string> Mdic = new Dictionary<string, string>();

            Mdic.Add("1", ".NET");   //1 juftliklar soni
            Mdic.Add("2", "C#");     //2
            Mdic.Add("3", "Asp.NET");//3
            Mdic.Add("4", "LINQ");   //4

            Console.WriteLine($"juftliklar soni : {Mdic.Count}");

            Dictionary<string, string>.KeyCollection KColl = Mdic.Keys;

            foreach (var item in KColl)
            {
                 Console.WriteLine($"kalit - {item}");
     }
```

![](/files/-MePZ40v8aIngo_3RaMr)

```csharp
    Dictionary<string, string> Mdic = new Dictionary<string, string>();

            Mdic.Add("1", ".NET");   //1 juftliklar soni
            Mdic.Add("2", "C#");     //2
            Mdic.Add("3", "Asp.NET");//3
            Mdic.Add("4", "LINQ");   //4

            Console.WriteLine($"juftliklar soni : {Mdic.Count}");

            Dictionary<string, string>.ValueCollection VColl = Mdic.Values;

            foreach (var item in VColl)
            {
                Console.WriteLine($"qiymat - {item}");
            }
```

![](/files/-MePZ40xchLHzER_lpyE)

```csharp
   static void Main(string[] args)
        {
            Dictionary<string, string> Mdic = new Dictionary<string, string>();

            Mdic.Add("1", ".NET");   //1 juftliklar soni
            Mdic.Add("2", "C#");     //2
            Mdic.Add("3", "Asp.NET");//3
            Mdic.Add("4", "LINQ");   //4

            Console.WriteLine($"juftliklar soni : {Mdic.Count}");

            Console.WriteLine("Clear........");
            Mdic.Clear(); // hamma elementlarni o`chirib yuboradi

            Console.WriteLine($"juftliklar soni : {Mdic.Count}");
        }
```

![](/files/-MePZ40ygRRfQKAbEqPm)

```csharp
    static void Main(string[] args)
        {
            Dictionary<string, string> Mdic = new Dictionary<string, string>();

            Mdic.Add("1", ".NET");   //1 juftliklar soni
            Mdic.Add("2", "C#");     //2
            Mdic.Add("3", "Asp.NET");//3
            Mdic.Add("4", "LINQ");   //4

            Console.WriteLine($"juftliklar soni : {Mdic.Count}");

            foreach (var item in Mdic)
            {
                Console.WriteLine($"kalit - {item.Key}   qiymat - {item.Value}");
            }

            Console.WriteLine("****************************");

            Mdic.Remove("1"); //kaliti 1 ga teng bo`lgan juftlikni o`chirib tashlaydi
            Mdic.Remove("2"); //kaliti 2 ga teng bo`lgan juftlikni o`chirib tashlaydi

            Console.WriteLine($"juftliklar soni : {Mdic.Count}");

            foreach (var item in Mdic)
            {
                Console.WriteLine($"kalit - {item.Key}   qiymat - {item.Value}");
            }
        }
```

![](/files/-MePZ40zOM-gmqiBKc5z)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.dot-net.uz/c-.net/basic/yuqori-daraja/toplamlar/dictionary.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
