Skip to content

Commit

Permalink
bob: fix if-statements example code (#2182)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Sep 28, 2023
1 parent f9dd4c0 commit 60212a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions exercises/practice/bob/.approaches/if/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

```csharp
using System.Linq;

public static class Bob
{
public static string Response(string message)
Expand All @@ -21,17 +22,17 @@ public static class Bob
return "Whatever.";
}

private bool IsSilence(string message)
private static bool IsSilence(string message)
{
return string.IsNullOrWhiteSpace(message);
}

private bool IsYell(string message)
private static bool IsYell(string message)
{
return message.Any(char.IsLetter) && message.ToUpperInvariant() == message;
}

private bool IsQuestion(string message)
private static bool IsQuestion(string message)
{
return message.TrimEnd().EndsWith("?");
}
Expand Down Expand Up @@ -97,14 +98,14 @@ Your team may choose to overrule them.
When the body of a function is a single expression, the function can be implemented as a [member-bodied expression][member-bodied-expressions], like so

```csharp
private bool IsSilence(string message) =>
private static bool IsSilence(string message) =>
string.IsNullOrWhiteSpace(message);
```

or

```csharp
private bool IsSilence(string message) => string.IsNullOrWhiteSpace(message);
private static bool IsSilence(string message) => string.IsNullOrWhiteSpace(message);
```

A [ternary operator][ternary operator] can be used to shorten the code and make the logic more efficient, like so
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/bob/.approaches/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ public static string Response(string message)
return "Whatever.";
}

private bool IsSilence(string message)
private static bool IsSilence(string message)
{
return string.IsNullOrWhiteSpace(message);
}

private bool IsYell(string message)
private static bool IsYell(string message)
{
return message.Any(char.IsLetter) && message.ToUpperInvariant() == message;
}

private bool IsQuestion(string message)
private static bool IsQuestion(string message)
{
return message.TrimEnd().EndsWith("?");
}
Expand Down

0 comments on commit 60212a7

Please sign in to comment.