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
m (Sites)
m (Don moved page CSharp Links to Notes on CSharp)
 
(2 intermediate revisions by the same user not shown)
Line 8: Line 8:
 
=== SanFoundry.com ===
 
=== SanFoundry.com ===
 
:* https://www.sanfoundry.com/csharp-programming-examples/
 
:* https://www.sanfoundry.com/csharp-programming-examples/
 +
 +
=== TutorialsTeacher.com ===
 +
: ''C# Tutorials''
 +
: URL: <small>https://www.tutorialsteacher.com/csharp/csharp-tutorials</small>
  
 
== Topic ==
 
== Topic ==
 +
===  null coalescing operator (??) ===
 +
; What do two question marks together mean in C#?
 +
: he double-question mark is a 'null coalescing operator' which means "If whatever is to the left is not null, use that, otherwise use what's to the right."
 +
:* <small>https://stackoverflow.com/questions/446835/what-do-two-question-marks-together-mean-in-c</small>
 +
'''Example:'''
 +
<pre style="background:black; color:green; padding:.7em; width:800px">
 +
// y = x, unless x is null, in which case y = -1.
 +
int y = x ?? -1;
 +
</pre>
 +
 
=== Associative arrays ===
 
=== Associative arrays ===
 
====With List<> data type:====
 
====With List<> data type:====

Latest revision as of 15:47, 29 June 2020


Sites

DotNetPerls.com

1000 C# Programming examples

SanFoundry.com

TutorialsTeacher.com

C# Tutorials
URL: https://www.tutorialsteacher.com/csharp/csharp-tutorials

Topic

null coalescing operator (??)

What do two question marks together mean in C#?
he double-question mark is a 'null coalescing operator' which means "If whatever is to the left is not null, use that, otherwise use what's to the right."

Example:

// y = x, unless x is null, in which case y = -1.
int y = x ?? -1;

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