forked from dotnet/samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish getstarted tutorials (dotnet#4330)
* upgrade to .NET 5 Top level statements, new TFM * update to .NET 5 Add top level statements Add missing samples from article. * update to .NET 5 Use top level statements for simplicity
- Loading branch information
1 parent
a994004
commit a39cf54
Showing
6 changed files
with
251 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,97 @@ | ||
using System; | ||
|
||
namespace BranchesAndLoops | ||
ExploreIf(); | ||
|
||
ExploreLoops(); | ||
|
||
ChallengeAnswer(); | ||
|
||
void ExploreIf() | ||
{ | ||
class Program | ||
int a = 5; | ||
int b = 3; | ||
if (a + b > 10) | ||
{ | ||
static void ExploreIf() | ||
{ | ||
int a = 5; | ||
int b = 3; | ||
if (a + b > 10) | ||
{ | ||
Console.WriteLine("The answer is greater than 10"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("The answer is not greater than 10"); | ||
} | ||
Console.WriteLine("The answer is greater than 10"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("The answer is not greater than 10"); | ||
} | ||
|
||
int c = 4; | ||
if ((a + b + c > 10) && (a > b)) | ||
{ | ||
Console.WriteLine("The answer is greater than 10"); | ||
Console.WriteLine("And the first number is greater than the second"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("The answer is not greater than 10"); | ||
Console.WriteLine("Or the first number is not greater than the second"); | ||
} | ||
int c = 4; | ||
if ((a + b + c > 10) && (a > b)) | ||
{ | ||
Console.WriteLine("The answer is greater than 10"); | ||
Console.WriteLine("And the first number is greater than the second"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("The answer is not greater than 10"); | ||
Console.WriteLine("Or the first number is not greater than the second"); | ||
} | ||
|
||
if ((a + b + c > 10) || (a > b)) | ||
{ | ||
Console.WriteLine("The answer is greater than 10"); | ||
Console.WriteLine("Or the first number is greater than the second"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("The answer is not greater than 10"); | ||
Console.WriteLine("And the first number is not greater than the second"); | ||
} | ||
} | ||
if ((a + b + c > 10) || (a > b)) | ||
{ | ||
Console.WriteLine("The answer is greater than 10"); | ||
Console.WriteLine("Or the first number is greater than the second"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("The answer is not greater than 10"); | ||
Console.WriteLine("And the first number is not greater than the second"); | ||
} | ||
} | ||
|
||
static void ChallengeAnswer() | ||
{ | ||
int sum = 0; | ||
for (int number = 1; number < 21; number++) | ||
{ | ||
if (number % 3 == 0) | ||
{ | ||
sum = sum + number; | ||
} | ||
} | ||
Console.WriteLine($"The sum is {sum}"); | ||
} | ||
void ExploreLoops() | ||
{ | ||
int counter = 0; | ||
while (counter < 10) | ||
{ | ||
Console.WriteLine($"Hello World! The counter is {counter}"); | ||
counter++; | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
ExploreIf(); | ||
counter = 0; | ||
do | ||
{ | ||
Console.WriteLine($"Hello World! The counter is {counter}"); | ||
counter++; | ||
} while (counter < 10); | ||
|
||
int counter = 0; | ||
while (counter < 10) | ||
{ | ||
Console.WriteLine($"Hello World! The counter is {counter}"); | ||
counter++; | ||
} | ||
for (int index = 0; index < 10; index++) | ||
{ | ||
Console.WriteLine($"Hello World! The index is {index}"); | ||
} | ||
|
||
counter = 0; | ||
do | ||
{ | ||
Console.WriteLine($"Hello World! The counter is {counter}"); | ||
counter++; | ||
} while (counter < 10); | ||
for (int row = 1; row < 11; row++) | ||
{ | ||
Console.WriteLine($"The row is {row}"); | ||
} | ||
for (char column = 'a'; column < 'k'; column++) | ||
{ | ||
Console.WriteLine($"The column is {column}"); | ||
} | ||
|
||
for (int index = 0; index < 10; index++) | ||
{ | ||
Console.WriteLine($"Hello World! The index is {index}"); | ||
} | ||
for (int row = 1; row < 11; row++) | ||
{ | ||
for (char column = 'a'; column < 'k'; column++) | ||
{ | ||
Console.WriteLine($"The cell is ({row}, {column})"); | ||
} | ||
} | ||
} | ||
|
||
ChallengeAnswer(); | ||
void ChallengeAnswer() | ||
{ | ||
int sum = 0; | ||
for (int number = 1; number < 21; number++) | ||
{ | ||
if (number % 3 == 0) | ||
{ | ||
sum = sum + number; | ||
} | ||
} | ||
Console.WriteLine($"The sum is {sum}"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace list_quickstart | ||
WorkWithString(); | ||
|
||
var fibonacciNumbers = new List<int> { 1, 1 }; | ||
|
||
while (fibonacciNumbers.Count < 20) | ||
{ | ||
class Program | ||
var previous = fibonacciNumbers[fibonacciNumbers.Count - 1]; | ||
var previous2 = fibonacciNumbers[fibonacciNumbers.Count - 2]; | ||
|
||
fibonacciNumbers.Add(previous + previous2); | ||
} | ||
foreach (var item in fibonacciNumbers) | ||
Console.WriteLine(item); | ||
|
||
void WorkWithString() | ||
{ | ||
var names = new List<string> { "<name>", "Ana", "Felipe" }; | ||
foreach (var name in names) | ||
{ | ||
Console.WriteLine($"Hello {name.ToUpper()}!"); | ||
} | ||
|
||
Console.WriteLine(); | ||
names.Add("Maria"); | ||
names.Add("Bill"); | ||
names.Remove("Ana"); | ||
foreach (var name in names) | ||
{ | ||
Console.WriteLine($"Hello {name.ToUpper()}!"); | ||
} | ||
|
||
Console.WriteLine($"My name is {names[0]}"); | ||
Console.WriteLine($"I've added {names[2]} and {names[3]} to the list"); | ||
|
||
Console.WriteLine($"The list has {names.Count} people in it"); | ||
|
||
var index = names.IndexOf("Felipe"); | ||
if (index == -1) | ||
{ | ||
Console.WriteLine($"When an item is not found, IndexOf returns {index}"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"The name {names[index]} is at index {index}"); | ||
} | ||
|
||
index = names.IndexOf("Not Found"); | ||
if (index == -1) | ||
{ | ||
Console.WriteLine($"When an item is not found, IndexOf returns {index}"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"The name {names[index]} is at index {index}"); | ||
|
||
} | ||
|
||
names.Sort(); | ||
foreach (var name in names) | ||
{ | ||
#region WorkingWithStrings | ||
static void Main(string[] args) | ||
{ | ||
WorkingWithStrings(); | ||
|
||
var fibonacciNumbers = new List<int> { 1, 1 }; | ||
|
||
while (fibonacciNumbers.Count < 20) | ||
{ | ||
var previous = fibonacciNumbers[fibonacciNumbers.Count - 1]; | ||
var previous2 = fibonacciNumbers[fibonacciNumbers.Count - 2]; | ||
|
||
fibonacciNumbers.Add(previous + previous2); | ||
} | ||
foreach (var item in fibonacciNumbers) | ||
Console.WriteLine(item); | ||
} | ||
|
||
public static void WorkingWithStrings() | ||
{ | ||
var names = new List<string> { "<name>", "Ana", "Felipe" }; | ||
foreach (var name in names) | ||
{ | ||
Console.WriteLine($"Hello {name.ToUpper()}!"); | ||
} | ||
|
||
Console.WriteLine(); | ||
names.Add("Maria"); | ||
names.Add("Bill"); | ||
names.Remove("Ana"); | ||
foreach (var name in names) | ||
{ | ||
Console.WriteLine($"Hello {name.ToUpper()}!"); | ||
} | ||
|
||
Console.WriteLine($"My name is {names[0]}"); | ||
Console.WriteLine($"I've added {names[2]} and {names[3]} to the list"); | ||
|
||
Console.WriteLine($"The list has {names.Count} people in it"); | ||
|
||
var index = names.IndexOf("Felipe"); | ||
Console.WriteLine($"The name {names[index]} is at index {index}"); | ||
|
||
var notFound = names.IndexOf("Not Found"); | ||
Console.WriteLine($"When an item is not found, IndexOf returns {notFound}"); | ||
|
||
names.Sort(); | ||
foreach (var name in names) | ||
{ | ||
Console.WriteLine($"Hello {name.ToUpper()}!"); | ||
} | ||
} | ||
#endregion | ||
Console.WriteLine($"Hello {name.ToUpper()}!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.