Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created May 28, 2021 15:14
Show Gist options
  • Save guitarrapc/a78611cb2cad0be588695c895f49cc6a to your computer and use it in GitHub Desktop.
Save guitarrapc/a78611cb2cad0be588695c895f49cc6a to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
namespace Sample
{
public class Class
{
public void M()
{
var dic1 = new Dictionary<string, string>()
{
// C# 3.0~
{ "foo", "bar"},
};
var dic2 = new Dictionary<string, string>()
{
// C# 6.0~
["foo"] = "bar",
};
// target typed new (C# 9.0 ~)
Dictionary<string, string> dic3 = new()
{
{ "foo", "bar" },
};
Dictionary<string, string> dic4 = new ()
{
["foo"] = "bar",
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment