Author : MD TAREQ HASSAN

Right padding according to max item

var maxItem = 13; // FindMaxItem()
int digits = (int)Math.Floor(Math.Log10(maxItem) + 1);

for(var j = 1; j <= itemsCount; j++){
  
  rowString += $"{j.ToString().PadRight(digits)} ";
  
  // ... ... ...
}

Writing to output window

Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Debug.WriteLine("\n\n---------");
            Debug.WriteLine("| start |");
            Debug.WriteLine("-------------------------------------------------------------------------------------------");


            // debug print here


            Debug.WriteLine("-------------------------------------------------------------------------------------------");
            Debug.WriteLine("|  end  |");
            Debug.WriteLine("---------\n\n");
        }
    }
}

Check valid email address

Solution from microsoft: https://docs.microsoft.com/en-us/dotnet/standard/base-types/how-to-verify-that-strings-are-in-valid-email-format


Using MailAddress class (courtesy: https://stackoverflow.com/a/5342460/4802664 & https://lonewolfonline.net/validate-email-addresses/)

public bool IsEmailValid(string emailaddress)
{
    try
    {
        MailAddress m = new MailAddress(emailaddress);
        return true;
    }
    catch (FormatException)
    {
        return false;
    }
}


Using RegEx (StackOverflow: https://stackoverflow.com/a/25609686)

[RegularExpression("/^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$/", ErrorMessage = "Lorem ipsum bla bla")]