D. Edward Mitchell 16:00, 14 April 2020 (UTC) Hello World!    groupKOS Developer Share UNDER CONSTRUCTION

Difference between revisions of "Notes on CSharp"

From groupKOS Developer Share
Jump to navigation Jump to search
(Created page with "Category: csharp Category: code == Sites == === DotNetPerls.com === :* https://www.dotnetperls.com/ === 1000 C# Programming examples === :* https://www.sanfoundry.com...")
 
m (Sites)
Line 6: Line 6:
 
:* https://www.dotnetperls.com/
 
:* https://www.dotnetperls.com/
 
=== 1000 C# Programming examples ===
 
=== 1000 C# Programming examples ===
 +
=== SanFoundry.com ===
 
:* https://www.sanfoundry.com/csharp-programming-examples/
 
:* https://www.sanfoundry.com/csharp-programming-examples/
  

Revision as of 12:39, 25 June 2020


Sites

DotNetPerls.com

1000 C# Programming examples

SanFoundry.com

Topic

Associative arrays

With List<> data type:

Retrieved 14:35, 23 June 2020 (UTC) from https://www.dotnetperls.com/keyvaluepair

// Part 1: create a List of KeyValuePairs.
var list = new List<KeyValuePair<string, int>>();
list.Add(new KeyValuePair<string, int>("Cat", 1));
list.Add(new KeyValuePair<string, int>("Dog", 2));
list.Add(new KeyValuePair<string, int>("Rabbit", 4));

// Part 2: loop over list and print pairs.
foreach (var element in list)
{
    Console.WriteLine(element);
}

With Dictionary data type:

var article = new Dictionary<string, dynamic>();

article["title"] = "Article Title";
article["description"] = "Article Description";
article["total_pages"] = 15;

int pages = article["total_pages"];
string title = article["title"];

Retrieved 14:35, 23 June 2020 (UTC) from https://stackoverflow.com/questions/35130242/c-sharp-collection-or-array-with-string-keys-and-values-of-different-types

With an ExpandoObject:

dynamic article = new ExpandoObject();
article.Title = "Article Title";
article.Description = "Article Description";
article.TotalPages = 15;

int pages = article.TotalPages;
string title = article.Title;

Retrieved 14:35, 23 June 2020 (UTC) from https://stackoverflow.com/questions/35130242/c-sharp-collection-or-array-with-string-keys-and-values-of-different-types