-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add project file and modernize code #10975
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
4 commits
Select commit
Hold shift + click to select a range
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
32 changes: 16 additions & 16 deletions
32
snippets/csharp/System/NullReferenceException/Overview/Array1.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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
// <Snippet8> | ||
using System; | ||
using System; | ||
|
||
public class Example | ||
public class Array1Example | ||
{ | ||
public static void Main() | ||
{ | ||
String[] values = { "one", null, "two" }; | ||
for (int ctr = 0; ctr <= values.GetUpperBound(0); ctr++) | ||
Console.Write("{0}{1}", values[ctr].Trim(), | ||
ctr == values.GetUpperBound(0) ? "" : ", "); | ||
Console.WriteLine(); | ||
} | ||
public static void Main() | ||
{ | ||
// <Snippet8> | ||
string[] values = [ "one", null, "two" ]; | ||
for (int ctr = 0; ctr <= values.GetUpperBound(0); ctr++) | ||
Console.Write("{0}{1}", values[ctr].Trim(), | ||
ctr == values.GetUpperBound(0) ? "" : ", "); | ||
Console.WriteLine(); | ||
|
||
// The example displays the following output: | ||
// Unhandled Exception: | ||
// System.NullReferenceException: Object reference not set to an instance of an object. | ||
// </Snippet8> | ||
} | ||
} | ||
// The example displays the following output: | ||
// Unhandled Exception: | ||
// System.NullReferenceException: Object reference not set to an instance of an object. | ||
// at Example.Main() | ||
// </Snippet8> |
31 changes: 16 additions & 15 deletions
31
snippets/csharp/System/NullReferenceException/Overview/Array2.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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
// <Snippet9> | ||
using System; | ||
using System; | ||
|
||
public class Example | ||
public class Array2Example | ||
{ | ||
public static void Main() | ||
{ | ||
String[] values = { "one", null, "two" }; | ||
for (int ctr = 0; ctr <= values.GetUpperBound(0); ctr++) | ||
Console.Write("{0}{1}", | ||
values[ctr] != null ? values[ctr].Trim() : "", | ||
ctr == values.GetUpperBound(0) ? "" : ", "); | ||
Console.WriteLine(); | ||
} | ||
public static void Main() | ||
{ | ||
// <Snippet9> | ||
string[] values = [ "one", null, "two" ]; | ||
for (int ctr = 0; ctr <= values.GetUpperBound(0); ctr++) | ||
Console.Write("{0}{1}", | ||
values[ctr] != null ? values[ctr].Trim() : "", | ||
ctr == values.GetUpperBound(0) ? "" : ", "); | ||
gewarren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Console.WriteLine(); | ||
|
||
// The example displays the following output: | ||
// one, , two | ||
// </Snippet9> | ||
} | ||
} | ||
// The example displays the following output: | ||
// one, , two | ||
// </Snippet9> |
33 changes: 17 additions & 16 deletions
33
snippets/csharp/System/NullReferenceException/Overview/Array3.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 |
---|---|---|
@@ -1,20 +1,21 @@ | ||
// <Snippet10> | ||
using System; | ||
using System; | ||
|
||
public class Example | ||
public class Array3Example | ||
{ | ||
public static void Main() | ||
{ | ||
int[] values = null; | ||
for (int ctr = 0; ctr <= 9; ctr++) | ||
values[ctr] = ctr * 2; | ||
public static void Main() | ||
{ | ||
// <Snippet10> | ||
int[] values = null; | ||
for (int ctr = 0; ctr <= 9; ctr++) | ||
values[ctr] = ctr * 2; | ||
|
||
foreach (var value in values) | ||
Console.WriteLine(value); | ||
} | ||
foreach (int value in values) | ||
Console.WriteLine(value); | ||
|
||
// The example displays the following output: | ||
// Unhandled Exception: | ||
// System.NullReferenceException: Object reference not set to an instance of an object. | ||
// at Array3Example.Main() | ||
// </Snippet10> | ||
} | ||
} | ||
// The example displays the following output: | ||
// Unhandled Exception: | ||
// System.NullReferenceException: Object reference not set to an instance of an object. | ||
// at Example.Main() | ||
// </Snippet10> |
47 changes: 24 additions & 23 deletions
47
snippets/csharp/System/NullReferenceException/Overview/Array4.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 |
---|---|---|
@@ -1,27 +1,28 @@ | ||
// <Snippet11> | ||
using System; | ||
using System; | ||
|
||
public class Example | ||
public class Array4Example | ||
{ | ||
public static void Main() | ||
{ | ||
int[] values = new int[10]; | ||
for (int ctr = 0; ctr <= 9; ctr++) | ||
values[ctr] = ctr * 2; | ||
public static void Main() | ||
{ | ||
// <Snippet11> | ||
int[] values = new int[10]; | ||
for (int ctr = 0; ctr <= 9; ctr++) | ||
values[ctr] = ctr * 2; | ||
|
||
foreach (var value in values) | ||
Console.WriteLine(value); | ||
} | ||
foreach (int value in values) | ||
Console.WriteLine(value); | ||
|
||
// The example displays the following output: | ||
// 0 | ||
// 2 | ||
// 4 | ||
// 6 | ||
// 8 | ||
// 10 | ||
// 12 | ||
// 14 | ||
// 16 | ||
// 18 | ||
// </Snippet11> | ||
} | ||
} | ||
// The example displays the following output: | ||
// 0 | ||
// 2 | ||
// 4 | ||
// 6 | ||
// 8 | ||
// 10 | ||
// 12 | ||
// 14 | ||
// 16 | ||
// 18 | ||
// </Snippet11> |
120 changes: 65 additions & 55 deletions
120
snippets/csharp/System/NullReferenceException/Overview/Chain1.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 |
---|---|---|
@@ -1,62 +1,72 @@ | ||
// <Snippet6> | ||
using System; | ||
using System; | ||
|
||
public class Example | ||
namespace Chain1 | ||
{ | ||
public static void Main() | ||
{ | ||
var pages = new Pages(); | ||
if (!String.IsNullOrEmpty(pages.CurrentPage.Title)) { | ||
String title = pages.CurrentPage.Title; | ||
Console.WriteLine("Current title: '{0}'", title); | ||
} | ||
} | ||
} | ||
// <Snippet6> | ||
public class Chain1Example | ||
{ | ||
public static void Main() | ||
{ | ||
var pages = new Pages(); | ||
if (!string.IsNullOrEmpty(pages.CurrentPage.Title)) | ||
{ | ||
string title = pages.CurrentPage.Title; | ||
Console.WriteLine($"Current title: '{title}'"); | ||
} | ||
} | ||
} | ||
|
||
public class Pages | ||
{ | ||
Page[] page = new Page[10]; | ||
int ctr = 0; | ||
public class Pages | ||
{ | ||
readonly Page[] _page = new Page[10]; | ||
int _ctr = 0; | ||
|
||
public Page CurrentPage | ||
{ | ||
get { return page[ctr]; } | ||
set { | ||
// Move all the page objects down to accommodate the new one. | ||
if (ctr > page.GetUpperBound(0)) { | ||
for (int ndx = 1; ndx <= page.GetUpperBound(0); ndx++) | ||
page[ndx - 1] = page[ndx]; | ||
} | ||
page[ctr] = value; | ||
if (ctr < page.GetUpperBound(0)) | ||
ctr++; | ||
} | ||
} | ||
public Page CurrentPage | ||
{ | ||
get { return _page[_ctr]; } | ||
set | ||
{ | ||
// Move all the page objects down to accommodate the new one. | ||
if (_ctr > _page.GetUpperBound(0)) | ||
{ | ||
for (int ndx = 1; ndx <= _page.GetUpperBound(0); ndx++) | ||
_page[ndx - 1] = _page[ndx]; | ||
} | ||
_page[_ctr] = value; | ||
if (_ctr < _page.GetUpperBound(0)) | ||
_ctr++; | ||
} | ||
} | ||
|
||
public Page PreviousPage | ||
{ | ||
get { | ||
if (ctr == 0) { | ||
if (page[0] == null) | ||
return null; | ||
else | ||
return page[0]; | ||
} | ||
else { | ||
ctr--; | ||
return page[ctr + 1]; | ||
} | ||
} | ||
} | ||
} | ||
public Page PreviousPage | ||
{ | ||
get | ||
{ | ||
if (_ctr == 0) | ||
{ | ||
if (_page[0] is null) | ||
return null; | ||
else | ||
return _page[0]; | ||
} | ||
else | ||
{ | ||
_ctr--; | ||
return _page[_ctr + 1]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class Page | ||
{ | ||
public Uri URL; | ||
public String Title; | ||
public class Page | ||
{ | ||
public Uri URL; | ||
public string Title; | ||
} | ||
|
||
// The example displays the following output: | ||
// Unhandled Exception: | ||
// System.NullReferenceException: Object reference not set to an instance of an object. | ||
// at Chain1Example.Main() | ||
// </Snippet6> | ||
} | ||
// The example displays the following output: | ||
// Unhandled Exception: | ||
// System.NullReferenceException: Object reference not set to an instance of an object. | ||
// at Example.Main() | ||
// </Snippet6> |
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.