Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ from student in students
group student by student.Last[0];
//</snippet10>



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


//<snippet12>
// Iterate group items with a nested foreach. This IGrouping encapsulates
Expand All @@ -56,10 +53,9 @@ orderby g.Key
}
//</snippet12>


//<Snippet13>
// Same as previous example except we use the entire last name as a key.
// Query variable is an IEnumerable<IGrouping<string, Student>>
// Same as previous example except we use the entire last name as a key.
// Query variable is an IEnumerable<IGrouping<string, Student>>
var studentQuery3 =
from student in students
group student by student.Last;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;

namespace operators
{
public static class IndexOperatorExamples
{
public static void Examples()
{
Arrays();
Indexers();
}

private static void Arrays()
{
// <SnippetArrays>
int[] fib = new int[10];
fib[0] = fib[1] = 1;
for (int i = 2; i < fib.Length; i++)
{
fib[i] = fib[i - 1] + fib[i - 2];
}
Console.WriteLine(fib[fib.Length - 1]); // output: 55

double[,] matrix = new double[2,2];
matrix[0,0] = 1.0;
matrix[0,1] = 2.0;
matrix[1,0] = matrix[1,1] = 3.0;
var determinant = matrix[0,0] * matrix[1,1] - matrix[1,0] * matrix[0,1];
Console.WriteLine(determinant); // output: -3
// </SnippetArrays>
}

private static void Indexers()
{
// <SnippetIndexers>
var dict = new Dictionary<string, double>();
dict["one"] = 1;
dict["pi"] = Math.PI;
Console.WriteLine(dict["one"] + dict["pi"]);
// </SnippetIndexers>
}
}
}
4 changes: 4 additions & 0 deletions snippets/csharp/language-reference/operators/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ static void Main(string[] args)
Console.WriteLine("======= >, <, >=, and <= operator examples =====");
GreaterAndLessOperatorsExamples.Examples();
Console.WriteLine();

Console.WriteLine("============== [] operator examples ============");
IndexOperatorExamples.Examples();
Console.WriteLine();
}
}
}