Passaggio all'ora solare 26 ottobre 2025 03:00 02:00 sposta indietro l'orologio di 1 ora (si dorme 1 ora in più)
Un Extension method C# per la classe String che implementa la funzione IsNullOrWhiteSpace presente dal Framework 4.0.

C#

namespace Sgart
{
    public static class Extensions
    {
        public static bool IsNullOrWhiteSpace(this string str)
        {
            if (str == null)
            {
                return true;
            }
            else if (str == string.Empty)
            {
                return true;
            }
            else if (str.Trim().Length == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
rispetto al metodo IsNullOrEmpty della classe string, questo metodo ritorna true anche se la stringa è composta solo da uno o più spazi.

Un esempio di come usarla:

C#

string test = "  ";
if(string.IsNullOrWhiteSpace()){
  Console.WriteLine("non valida");
}
Tags:
C#241 Esempi228
Potrebbe interessarti anche: