Check if the variable is an empty string - CSharp Language Basics

CSharp examples for Language Basics:string

Description

Check if the variable is an empty string

Demo Code

// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using Microsoft.Data.Tools.XmlDesignerBase.Common;
using System;/*w w  w  .  j  a v a  2s.c o m*/

public class Main{
        /// <summary>
        ///     Check if the variable is an empty string
        /// </summary>
        /// <param name="variable">The value to check</param>
        /// <param name="variableName">The name of the variable being checked</param>
        /// <exception cref="ArgumentException" />
        /// <exception cref="ArgumentNullException" />
        public static void CheckForEmptyString(string variable, string variableName)
        {
            CheckForNullReference(variable, variableName);
            CheckForNullReference(variableName, "variableName");
            if (variable.Length == 0)
            {
                throw new ArgumentException(
                    CommonResourceUtil.GetString(CommonResource.ExceptionEmptyString, variableName));
            }
        }
}

Related Tutorials