Skip to content

Commit 24af3ab

Browse files
author
Ron Petrusha
authored
Revised code for consuming a class library (#103)
1 parent 92afb51 commit 24af3ab

File tree

2 files changed

+36
-15
lines changed
  • snippets
    • core/tutorials/vb-library-with-visual-studio
    • csharp/getting_started/with_visual_studio_2017

2 files changed

+36
-15
lines changed
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
Imports UtilityLibraries
22

33
Module Program
4-
Sub Main()
5-
Dim rows As Integer = Console.WindowHeight
4+
Dim row As Integer = 0
65

7-
Console.Clear()
6+
Sub Main()
87
Do
9-
If Console.CursorTop >= rows OrElse Console.CursorTop = 0 Then
10-
Console.Clear()
11-
Console.WriteLine("\nPress <Enter> only to exit; otherwise, enter a string and press <Enter>:\n")
12-
End If
8+
If row = 0 OrElse row >= 25 Then ResetConsole()
9+
1310
Dim input As String = Console.ReadLine()
1411
If String.IsNullOrEmpty(input) Then Return
1512

1613
Console.WriteLine($"Input: {input} {"Begins with uppercase? ",30}: " +
1714
$"{If(input.StartsWithUpper(), "Yes", "No")} {vbCrLf}")
15+
row += 3
1816
Loop While True
1917
End Sub
18+
19+
Private Sub ResetConsole()
20+
If row > 0 Then
21+
Console.WriteLine("Press any key to continue...")
22+
Console.ReadKey()
23+
End If
24+
Console.Clear()
25+
Console.WriteLine("{0}Press <Enter> only to exit; otherwise, enter a string and press <Enter>:{0}",
26+
vbCrLf)
27+
row = 3
28+
End Sub
2029
End Module
30+

snippets/csharp/getting_started/with_visual_studio_2017/showcase.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,32 @@ class Program
55
{
66
static void Main(string[] args)
77
{
8-
int rows = Console.WindowHeight;
9-
10-
Console.Clear();
8+
int row = 0;
9+
1110
do
1211
{
13-
if (Console.CursorTop >= rows || Console.CursorTop == 0)
14-
{
15-
Console.Clear();
16-
Console.WriteLine("\nPress <Enter> only to exit; otherwise, enter a string and press <Enter>:\n");
17-
}
12+
if (row == 0 || row >= 25)
13+
ResetConsole();
14+
1815
string input = Console.ReadLine();
1916
if (String.IsNullOrEmpty(input)) break;
2017
Console.WriteLine($"Input: {input} {"Begins with uppercase? ",30}: " +
2118
$"{(input.StartsWithUpper() ? "Yes" : "No")}\n");
19+
row += 3;
2220
} while (true);
21+
return;
22+
23+
// Declare a ResetConsole local method
24+
void ResetConsole()
25+
{
26+
if (row > 0) {
27+
Console.WriteLine("Press any key to continue...");
28+
Console.ReadKey();
29+
}
30+
Console.Clear();
31+
Console.WriteLine("\nPress <Enter> only to exit; otherwise, enter a string and press <Enter>:\n");
32+
row = 3;
33+
}
2334
}
2435
}
2536

0 commit comments

Comments
 (0)