Skip to content

Commit 62ed616

Browse files
jimv3egonSchiele
authored andcommitted
add csharp examples (egonSchiele#10)
1 parent c3396b8 commit 62ed616

File tree

96 files changed

+107024
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+107024
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/bin/*
2+
**/obj/*
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": ".NET Core Launch (console)",
6+
"type": "coreclr",
7+
"request": "launch",
8+
"preLaunchTask": "build",
9+
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_binary_search.dll",
10+
"args": [],
11+
"cwd": "${workspaceRoot}",
12+
"externalConsole": false,
13+
"stopAtEntry": false,
14+
"internalConsoleOptions": "openOnSessionStart"
15+
},
16+
{
17+
"name": ".NET Core Attach",
18+
"type": "coreclr",
19+
"request": "attach",
20+
"processId": "${command.pickProcess}"
21+
}
22+
]
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "0.1.0",
3+
"command": "dotnet",
4+
"isShellCommand": true,
5+
"args": [],
6+
"tasks": [
7+
{
8+
"taskName": "build",
9+
"args": [
10+
"${workspaceRoot}/project.json"
11+
],
12+
"isBuildCommand": true,
13+
"problemMatcher": "$msCompile"
14+
}
15+
]
16+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace ConsoleApplication
6+
{
7+
public class Program
8+
{
9+
public static void Main(string[] args)
10+
{
11+
var myList = new List<int> { 1, 3, 5, 7, 9 };
12+
Console.WriteLine(BinarySearch(myList, 3)); // => 1
13+
Console.WriteLine(BinarySearch(myList, -1)); // => null gets printed as an empty string
14+
}
15+
16+
private static int? BinarySearch(IList<int> list, int item)
17+
{
18+
var low = 0;
19+
var high = list.Count() - 1;
20+
21+
while (low <= high)
22+
{
23+
var mid = (low + high) / 2;
24+
var guess = list[mid];
25+
if (guess == item) return mid;
26+
if (guess > item)
27+
{
28+
high = mid - 1;
29+
}
30+
else
31+
{
32+
low = mid + 1;
33+
}
34+
}
35+
36+
return null;
37+
}
38+
}
39+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "1.0.0-*",
3+
"buildOptions": {
4+
"debugType": "portable",
5+
"emitEntryPoint": true
6+
},
7+
"dependencies": {},
8+
"frameworks": {
9+
"netcoreapp1.0": {
10+
"dependencies": {
11+
"Microsoft.NETCore.App": {
12+
"type": "platform",
13+
"version": "1.0.1"
14+
}
15+
},
16+
"imports": "dnxcore50"
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)