Search Library in Add new project page in the search box. Select C# from the language list, and then select All platforms from the platform list. Select the Class Library template and click on the Next button.
Enter DemoLibrary in the Project name Box on Configure your new project page and click on theNext button.
Figure 2 Create a class library
Replace Class.cs with the following code and rename with StringLibrary named file and Save the file.
\using System;
namespace DemoLibrary
{
public static class StringLibrary
{
public static bool StartsWithLower(this string str)
{
if (string.IsNullOrWhiteSpace(str))
return false;
char ch = str[0];
return char.IsLower(ch);
}
}
}
The class library DemoLibrary.StringLibrary contains the StringLibrary method. . This method returns a Boolean value when the string starts with a Lower character.Char.IsLower() method returns true if a character is lower.
Select Build->Build solution or press CTR+SHIFT+B to verify that the project compiles without error.
Step 3: Add Console application to the solution
Add a “DemoConsole” console application that uses the class library. This application will prompt the user to enter a string and return true if the string contains a lower character.
Add .Net Console application named it “DemoConsole” to the solution.
Right-click on the solution and select Add->New Project from Solution Explorer..
Search Console in Add new project page in the search box. Select C# from the language list, and then select All platforms from the platform list. Select the Console Application template and click on the Next button.
Enter DemoConsole in the Project name Box on Configure your new project page and click on the Next button.
Figure 3 Create a console application
2.Replace Program.cs with the following code:
using System;
using DemoLibrary;
namespace DemoConsole
{
class Program
{
static void Main(string[] args)
{
int row = 0;
do
{
if (row == 0 || row >= 25)
ResetConsole();
string input = Console.ReadLine();
if (string.IsNullOrEmpty(input)) break;
Console.WriteLine($"Input: {input} {"Begins with lowercase? ",30}: " +
$"{(input.StartsWithUpper() ? "Yes" : "No")}\n");
row += 3;
} while (true);
return;
// Declare a ResetConsole local method
void ResetConsole()
{
if (row > 0)
{
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
Console.Clear();
Console.WriteLine("\nPress only to exit; otherwise, enter a string and press :\n");
row = 3;
}
}
}
}
The row variable is used to maintain a count number of rows written in console application when its value greater than 25 the code clear console application.