-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Update tutorials and program guide for modern extensions #50132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ed1fa8a
Update sample for LINQ tutorial
BillWagner e12c667
First pass edit
BillWagner 8dc7f38
Second proofread
BillWagner 767c3c9
Finish edits in classes and structs
BillWagner b8fcd03
Finish programming guide.
BillWagner a8c17ac
Apply suggestions from code review
BillWagner 8d7e65b
respond to reviews.
BillWagner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...ming-guide/classes-and-structs/how-to-create-a-new-method-for-an-enumeration.md
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
2 changes: 1 addition & 1 deletion
2
docs/csharp/programming-guide/generics/constraints-on-type-parameters.md
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
175 changes: 175 additions & 0 deletions
175
docs/csharp/tutorials/snippets/console-linq/InterimSteps.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| namespace UnusedCode; | ||
|
|
||
| using LinqFaroShuffle; | ||
| internal class InterimSteps | ||
| { | ||
| // <StepOne> | ||
| static IEnumerable<string> Suits() | ||
| { | ||
| yield return "clubs"; | ||
| yield return "diamonds"; | ||
| yield return "hearts"; | ||
| yield return "spades"; | ||
| } | ||
|
|
||
| static IEnumerable<string> Ranks() | ||
| { | ||
| yield return "two"; | ||
| yield return "three"; | ||
| yield return "four"; | ||
| yield return "five"; | ||
| yield return "six"; | ||
| yield return "seven"; | ||
| yield return "eight"; | ||
| yield return "nine"; | ||
| yield return "ten"; | ||
| yield return "jack"; | ||
| yield return "queen"; | ||
| yield return "king"; | ||
| yield return "ace"; | ||
| } | ||
| // </StepOne> | ||
|
|
||
| private static void InitialMain() | ||
| { | ||
| // <StepTwo> | ||
| var startingDeck = from s in Suits() | ||
| from r in Ranks() | ||
| select (Suit: s, Rank: r); | ||
|
|
||
| // Display each card that's generated and placed in startingDeck | ||
| foreach (var card in startingDeck) | ||
| { | ||
| Console.WriteLine(card); | ||
| } | ||
| // </StepTwo> | ||
|
|
||
| // <StepThree> | ||
| var top = startingDeck.Take(26); | ||
| var bottom = startingDeck.Skip(26); | ||
| // </StepThree> | ||
|
|
||
| } | ||
|
|
||
| private void StartShuffling() | ||
| { | ||
| var startingDeck = from s in Suits() | ||
| from r in Ranks() | ||
| select (Suit: s, Rank: r); | ||
|
|
||
| // Display each card that's generated and placed in startingDeck | ||
| foreach (var card in startingDeck) | ||
| { | ||
| Console.WriteLine(card); | ||
| } | ||
|
|
||
| var top = startingDeck.Take(26); | ||
| var bottom = startingDeck.Skip(26); | ||
|
|
||
| // <StepFive> | ||
| var shuffledDeck = top.InterleaveSequenceWith(bottom); | ||
|
|
||
| foreach (var c in shuffledDeck) | ||
| { | ||
| Console.WriteLine(c); | ||
| } | ||
| // </StepFive> | ||
| } | ||
|
|
||
| private void CompareSequences() | ||
| { | ||
| // <StepSix> | ||
| var startingDeck = from s in Suits() | ||
| from r in Ranks() | ||
| select (Suit: s, Rank: r); | ||
|
|
||
| // Display each card generated and placed in startingDeck in the console | ||
| foreach (var card in startingDeck) | ||
| { | ||
| Console.WriteLine(card); | ||
| } | ||
|
|
||
| var top = startingDeck.Take(26); | ||
| var bottom = startingDeck.Skip(26); | ||
|
|
||
| var shuffledDeck = top.InterleaveSequenceWith(bottom); | ||
|
|
||
| var times = 0; | ||
| // Re-use the shuffle variable from earlier, or you can make a new one | ||
| shuffledDeck = startingDeck; | ||
| do | ||
| { | ||
| shuffledDeck = shuffledDeck.Take(26).InterleaveSequenceWith(shuffledDeck.Skip(26)); | ||
|
|
||
| foreach (var card in shuffledDeck) | ||
| { | ||
| Console.WriteLine(card); | ||
| } | ||
| Console.WriteLine(); | ||
| times++; | ||
|
|
||
| } while (!startingDeck.SequenceEquals(shuffledDeck)); | ||
|
|
||
| Console.WriteLine(times); | ||
| // </StepSix> | ||
| } | ||
|
|
||
| private void AddLogging() | ||
| { | ||
| // <StepSeven> | ||
| var startingDeck = (from s in Suits().LogQuery("Suit Generation") | ||
| from r in Ranks().LogQuery("Rank Generation") | ||
| select (Suit: s, Rank: r)).LogQuery("Starting Deck"); | ||
|
|
||
| foreach (var c in startingDeck) | ||
| { | ||
| Console.WriteLine(c); | ||
| } | ||
|
|
||
| Console.WriteLine(); | ||
| var times = 0; | ||
| var shuffle = startingDeck; | ||
|
|
||
| do | ||
| { | ||
| // Out shuffle | ||
| /* | ||
| shuffle = shuffle.Take(26) | ||
| .LogQuery("Top Half") | ||
| .InterleaveSequenceWith(shuffle.Skip(26) | ||
| .LogQuery("Bottom Half")) | ||
| .LogQuery("Shuffle"); | ||
| */ | ||
|
|
||
| // In shuffle | ||
| shuffle = shuffle.Skip(26).LogQuery("Bottom Half") | ||
| .InterleaveSequenceWith(shuffle.Take(26).LogQuery("Top Half")) | ||
| .LogQuery("Shuffle"); | ||
|
|
||
| foreach (var c in shuffle) | ||
| { | ||
| Console.WriteLine(c); | ||
| } | ||
|
|
||
| times++; | ||
| Console.WriteLine(times); | ||
| } while (!startingDeck.SequenceEquals(shuffle)); | ||
|
|
||
| Console.WriteLine(times); | ||
| // </StepSeven> | ||
| } | ||
| } | ||
|
|
||
| // <StepFour> | ||
| public static class CardExtensions | ||
| { | ||
| extension<T>(IEnumerable<T> sequence) | ||
| { | ||
| public IEnumerable<T> InterleaveSequenceWith(IEnumerable<T> second) | ||
| { | ||
| // Your implementation goes here | ||
| return default; | ||
| } | ||
| } | ||
| } | ||
| // </StepFour> |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.