Skip to content

Commit 08ddb0b

Browse files
committed
add project file and make it compile
1 parent d447e13 commit 08ddb0b

File tree

6 files changed

+41
-32
lines changed

6 files changed

+41
-32
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ConsoleApplication1.Program1.Main();

snippets/csharp/System/EventArgs/Overview/programnodata.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
namespace ConsoleApplication1
55
{
6-
class Program
6+
public class Program1
77
{
8-
static void Main(string[] args)
8+
public static void Main()
99
{
10-
Counter c = new Counter(new Random().Next(10));
10+
Counter c = new(new Random().Next(10));
1111
c.ThresholdReached += c_ThresholdReached;
1212

1313
Console.WriteLine("press 'a' key to increase total");
@@ -27,18 +27,18 @@ static void c_ThresholdReached(object sender, EventArgs e)
2727

2828
class Counter
2929
{
30-
private int threshold;
31-
private int total;
30+
private readonly int _threshold;
31+
private int _total;
3232

3333
public Counter(int passedThreshold)
3434
{
35-
threshold = passedThreshold;
35+
_threshold = passedThreshold;
3636
}
3737

3838
public void Add(int x)
3939
{
40-
total += x;
41-
if (total >= threshold)
40+
_total += x;
41+
if (_total >= _threshold)
4242
{
4343
OnThresholdReached(EventArgs.Empty);
4444
}

snippets/csharp/System/EventArgs/Overview/programtruncated.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using System;
22

3-
namespace ConsoleApplication1
3+
namespace ConsoleApplication2
44
{
55
// <snippet2>
6-
class Program
6+
public class Program2
77
{
8-
static void Main()
8+
public static void Main()
99
{
1010
var c = new Counter();
1111
c.ThresholdReached += c_ThresholdReached;

snippets/csharp/System/EventArgs/Overview/programwithdata.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// <snippet6>
22
using System;
33

4-
namespace ConsoleApplication1
4+
namespace ConsoleApplication3
55
{
6-
class Program
6+
public class Program3
77
{
8-
static void Main(string[] args)
8+
public static void Main(string[] args)
99
{
10-
Counter c = new Counter(new Random().Next(10));
10+
Counter c = new(new Random().Next(10));
1111
c.ThresholdReached += c_ThresholdReached;
1212

1313
Console.WriteLine("press 'a' key to increase total");
@@ -27,21 +27,21 @@ static void c_ThresholdReached(object? sender, ThresholdReachedEventArgs e)
2727

2828
class Counter
2929
{
30-
private int threshold;
31-
private int total;
30+
private readonly int _threshold;
31+
private int _total;
3232

3333
public Counter(int passedThreshold)
3434
{
35-
threshold = passedThreshold;
35+
_threshold = passedThreshold;
3636
}
3737

3838
public void Add(int x)
3939
{
40-
total += x;
41-
if (total >= threshold)
40+
_total += x;
41+
if (_total >= _threshold)
4242
{
4343
ThresholdReachedEventArgs args = new ThresholdReachedEventArgs();
44-
args.Threshold = threshold;
44+
args.Threshold = _threshold;
4545
args.TimeReached = DateTime.Now;
4646
OnThresholdReached(args);
4747
}

snippets/csharp/System/EventArgs/Overview/programwithdelegate.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// <snippet7>
22
using System;
33

4-
namespace ConsoleApplication1
4+
namespace ConsoleApplication4
55
{
6-
class Program
6+
class Program4
77
{
8-
static void Main(string[] args)
8+
public static void Main(string[] args)
99
{
10-
Counter c = new Counter(new Random().Next(10));
10+
Counter c = new(new Random().Next(10));
1111
c.ThresholdReached += c_ThresholdReached;
1212

1313
Console.WriteLine("press 'a' key to increase total");
@@ -18,7 +18,7 @@ static void Main(string[] args)
1818
}
1919
}
2020

21-
static void c_ThresholdReached(Object sender, ThresholdReachedEventArgs e)
21+
public static void c_ThresholdReached(object sender, ThresholdReachedEventArgs e)
2222
{
2323
Console.WriteLine("The threshold of {0} was reached at {1}.", e.Threshold, e.TimeReached);
2424
Environment.Exit(0);
@@ -27,21 +27,21 @@ static void c_ThresholdReached(Object sender, ThresholdReachedEventArgs e)
2727

2828
class Counter
2929
{
30-
private int threshold;
31-
private int total;
30+
private readonly int _threshold;
31+
private int _total;
3232

3333
public Counter(int passedThreshold)
3434
{
35-
threshold = passedThreshold;
35+
_threshold = passedThreshold;
3636
}
3737

3838
public void Add(int x)
3939
{
40-
total += x;
41-
if (total >= threshold)
40+
_total += x;
41+
if (_total >= _threshold)
4242
{
4343
ThresholdReachedEventArgs args = new ThresholdReachedEventArgs();
44-
args.Threshold = threshold;
44+
args.Threshold = _threshold;
4545
args.TimeReached = DateTime.Now;
4646
OnThresholdReached(args);
4747
}

0 commit comments

Comments
 (0)