Syntax

C# Create a Dictionary Syntax

In C#, create a dictionary: creates key-value pairs — var ages = new Dictionary<string, int>(); ages["Ada"] = 36;

Quick Answer

Syntax
var ages = new Dictionary<string, int>(); ages["Ada"] = 36;
C#Syntax

Create a Dictionary

Code example
var ages = new Dictionary<string, int>(); ages["Ada"] = 36;

Creates key-value pairs.

Learn More

How to create a dictionary in C#

  1. Open your C# file or editor.
  2. Copy the example, then replace its sample names and values for your code.

C# Create a Dictionary Syntax

Use var ages = new Dictionary<string, int>(); ages["Ada"] = 36;.

Related Syntax References

Frequently asked questions

What is the C# syntax for create a dictionary?

Use this pattern: var ages = new Dictionary<string, int>(); ages["Ada"] = 36;

Can I copy this C# code example?

Yes. Use Copy code and adapt the example to your program.

Is this C# syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify