C# – Build a .NET Standard library with Visual C# – Video

Following the Microsoft tutorial for building a .Net Standard library with Visual Basic from here, I have decided to make a video for .Net Standard library with C#. Pretty much, it is one and the same.

C# - Build a .NET Standard library with C# in Visual Studio 2019

The library contains one class and there is one method in the class, checking whether the first char of the string is an upper case or not:

using System;
namespace UtilityLibraries
{
    public static class StringLibrary
    {
        public static bool StartsWithUpper(this String str)
        {
            if (String.IsNullOrWhiteSpace(str))
            {
                return false;
            }

            Char ch = str[0];
            return Char.IsUpper(ch);
        }
    }
}

Once the “library” is created, some tests are built as well:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UtilityLibraries;

namespace StringLibraryTest
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestStartsWithUpper()
        {
            string[] words = { "Alphabet", "Zulu", "ABC", "Витош", "ВитошАкадемия.ком" };
            foreach (string word in words)
            {
                bool result = word.StartsWithUpper();
                Assert.IsTrue(result, String.Format("Expected for '{0}': true; Actual {1}",word, result));
            }
        }

        [TestMethod]
        public void TestDoesNotStartWithUpper()
        {
            string[] words = { "alphabet", "zulu", "aBC", "ш", "ком","55",".","" };
            foreach (string word in words)
            {
                bool result = word.StartsWithUpper();
                Assert.IsFalse(result, String.Format("Expected for '{0}': true; Actual {1}", word, result));
            }
        }

        [TestMethod]
        public void TestWithNullOrEmpty()
        {
            string[] words = {string.Empty, null};
            foreach (var word in words)
            {
                bool result = word.StartsWithUpper();
                Assert.IsFalse(result, String.Format("Expected for '{0}': false; Actual {1}",
                    word == null ? "" : word, result ));
            }
        }
    }
}

At the end, some show case is presented, showing the usage of the extension methods for the library. The code is a bit overcomplicated there, but this is how the tutorial looks like:

using System;
using UtilityLibraries;

class Startup
{
    static void Main()
    {
        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 uppercase? ",30}: " +
                              $"{(input.StartsWithUpper() ? "Yes" : "No")}\n");
            row += 3;
        } while (true);
        return;


        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 whole code in GitHub is here. Enjoy it!