Click here to Skip to main content
16,018,525 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii,
I have around 15 string values .. n for each i wanted to check wether they are empty or not if they are empty then i want to display an error that this string is empty .. but for each of this i am checking isnullor empty and returning an error message ... do you any way in which we can check all values at one go insted of checking each all time
Posted
Comments
Dholakiya Ankit 2-Aug-13 2:55am    
use array..

If your data comes from database, compare it to DBNull.Value[^]
 
Share this answer
 
Hi,

Add your all string value in List<string> .

say for example,
List<string> s = new List<string>();

s.add(your string value);
up to n time, you can do it in for loop.

Then check like this,

SQL
List<string> s1 = (from a in s
                    where string.IsNullOrEmpty(a)
                    select a.ToString()).ToList();



Check s1.Count(). If > 0 means you have string with blank value.
 
Share this answer
 
v4
Quote:
The following example examines three strings and determines whether each string has a value, is an empty string, or is null.


Code Sample

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string s1 = "abcd";
            string s2 = "";
            string s3 = null;

            Console.WriteLine("String s1 {0}.", Test(s1));
            Console.WriteLine("String s2 {0}.", Test(s2));
            Console.WriteLine("String s3 {0}.", Test(s3));
            Console.ReadLine();
        }

        public static String Test(string s)
        {
            if (String.IsNullOrEmpty(s))
                return "is null or empty";
            else
                return String.Format("(\"{0}\") is neither null nor empty", s);
        }
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900