Skip to content

Commit 3297a0f

Browse files
authored
Merge pull request #560 from dotnet/master
Update live with current master
2 parents 9141166 + e9f7aed commit 3297a0f

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

snippets/csharp/VS_Snippets_VBCSharp/CsCsrefQueryKeywords/CS/Group.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ from student in students
2626
group student by student.Last[0];
2727
//</snippet10>
2828

29-
30-
3129
// This query could be easily modified to group by the entire last name.
3230
//<Snippet11>
3331
// Group students by the first letter of their last name
@@ -39,7 +37,6 @@ orderby g.Key
3937
select g;
4038
//</snippet11>
4139
Console.WriteLine("The SimpleGroup method produces this output:\r\n");
42-
4340

4441
//<snippet12>
4542
// Iterate group items with a nested foreach. This IGrouping encapsulates
@@ -56,10 +53,9 @@ orderby g.Key
5653
}
5754
//</snippet12>
5855

59-
6056
//<Snippet13>
61-
// Same as previous example except we use the entire last name as a key.
62-
// Query variable is an IEnumerable<IGrouping<string, Student>>
57+
// Same as previous example except we use the entire last name as a key.
58+
// Query variable is an IEnumerable<IGrouping<string, Student>>
6359
var studentQuery3 =
6460
from student in students
6561
group student by student.Last;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace operators
5+
{
6+
public static class IndexOperatorExamples
7+
{
8+
public static void Examples()
9+
{
10+
Arrays();
11+
Indexers();
12+
}
13+
14+
private static void Arrays()
15+
{
16+
// <SnippetArrays>
17+
int[] fib = new int[10];
18+
fib[0] = fib[1] = 1;
19+
for (int i = 2; i < fib.Length; i++)
20+
{
21+
fib[i] = fib[i - 1] + fib[i - 2];
22+
}
23+
Console.WriteLine(fib[fib.Length - 1]); // output: 55
24+
25+
double[,] matrix = new double[2,2];
26+
matrix[0,0] = 1.0;
27+
matrix[0,1] = 2.0;
28+
matrix[1,0] = matrix[1,1] = 3.0;
29+
var determinant = matrix[0,0] * matrix[1,1] - matrix[1,0] * matrix[0,1];
30+
Console.WriteLine(determinant); // output: -3
31+
// </SnippetArrays>
32+
}
33+
34+
private static void Indexers()
35+
{
36+
// <SnippetIndexers>
37+
var dict = new Dictionary<string, double>();
38+
dict["one"] = 1;
39+
dict["pi"] = Math.PI;
40+
Console.WriteLine(dict["one"] + dict["pi"]);
41+
// </SnippetIndexers>
42+
}
43+
}
44+
}

snippets/csharp/language-reference/operators/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ static void Main(string[] args)
4949
Console.WriteLine("======= >, <, >=, and <= operator examples =====");
5050
GreaterAndLessOperatorsExamples.Examples();
5151
Console.WriteLine();
52+
53+
Console.WriteLine("============== [] operator examples ============");
54+
IndexOperatorExamples.Examples();
55+
Console.WriteLine();
5256
}
5357
}
5458
}

0 commit comments

Comments
 (0)