-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,71 @@ | ||
// <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: '{0}'", title); | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
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] == null) | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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 Example.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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,71 @@ | ||
// <Snippet7> | ||
using System; | ||
|
||
public class Example | ||
public class Chain2Example | ||
{ | ||
public static void Main() | ||
{ | ||
var pages = new Pages(); | ||
Page current = pages.CurrentPage; | ||
if (current != null) { | ||
String title = current.Title; | ||
Console.WriteLine("Current title: '{0}'", title); | ||
} | ||
else { | ||
Console.WriteLine("There is no page information in the cache."); | ||
} | ||
} | ||
public static void Main() | ||
{ | ||
var pages = new Pages(); | ||
Page current = pages.CurrentPage; | ||
if (current != null) | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something here seems off if nullable references are enabled. Either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have now explicitly disabled nullable context for the purpose of the examples. Can you review my most recent commit, especially the note I added to the NRE examples in the .xml file? |
||
{ | ||
string title = current.Title; | ||
Console.WriteLine("Current title: '{0}'", title); | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
else | ||
{ | ||
Console.WriteLine("There is no page information in the cache."); | ||
} | ||
} | ||
} | ||
// The example displays the following output: | ||
// There is no page information in the cache. | ||
// </Snippet7> | ||
|
||
public class Pages | ||
{ | ||
Page[] page = new Page[10]; | ||
int ctr = 0; | ||
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; | ||
public Page PreviousPage | ||
{ | ||
get | ||
{ | ||
if (_ctr == 0) | ||
{ | ||
if (_page[0] == null) | ||
return null; | ||
else | ||
return _page[0]; | ||
} | ||
else | ||
return page[0]; | ||
} | ||
else { | ||
ctr--; | ||
return page[ctr + 1]; | ||
} | ||
} | ||
} | ||
{ | ||
_ctr--; | ||
return _page[_ctr + 1]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class Page | ||
{ | ||
public Uri URL; | ||
public String Title; | ||
public Uri URL; | ||
public string Title; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Do something | ||
using System; | ||
|
||
Console.WriteLine("Hello World"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
Uh oh!
There was an error while loading. Please reload this page.