Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/core/docker/snippets/App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
var counter = 0;
var max = args.Length is not 0 ? Convert.ToInt32(args[0]) : -1;

while (max is -1 || counter < max)
// If a number is passed as a command-line argument,
// it will be used as the maximum counter value.
var max = args.Length > 0 && int.TryParse(args[0], out var parsedMax)
? parsedMax
: -1;

// Run indefinitely if no max value is provided
while (max == -1 || counter < max)
{
Console.WriteLine($"Counter: {++counter}");

await Task.Delay(TimeSpan.FromMilliseconds(1_000));
// Wait for one second between iterations
await Task.Delay(TimeSpan.FromSeconds(1));
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@ namespace ExpressionBodiedMembers;

public class Person
{
private string fname;
private string lname;

public Person(string firstName, string lastName)
{
fname = firstName;
lname = lastName;
}

private string fname;
private string lname;
public string FirstName { get; set }

public string LastName { get; set }

/// <summary>
/// Add some changes in methods
/// </summary>
/// <returns></returns>

public override string ToString() => $"{fname} {lname}".Trim();
public override string ToString() => $"{FirstName} {LastName}".Trim();
public void DisplayName() => Console.WriteLine(ToString());

// Expression-bodied methods with parameters
public string GetFullName(string title) => $"{title} {fname} {lname}";
public string GetFullName(string title) => $"{title} {FirstName} {LastName}";
public int CalculateAge(int birthYear) => DateTime.Now.Year - birthYear;
public bool IsOlderThan(int age) => CalculateAge(1990) > age;
public string FormatName(string format) => format.Replace("{first}", fname).Replace("{last}", lname);
public string FormatName(string format) => format.Replace("{first}", FirstName).Replace("{last}", LastName);
}

class Example
Expand Down
Loading