Tuesday, February 28, 2017

How to C# String Null

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
 public partial class Form1 : Form
 {
  public Form1()
  {
   InitializeComponent();
  }

  private void button1_Click(object sender, EventArgs e)
  {
   string str =null;

   if (str == null)
   {
    MessageBox.Show("String is null");
   }
   else
   {
    MessageBox.Show("String is not null");
   }

   str = "test";

   if (string.IsNullOrEmpty(str))
   {
    MessageBox.Show("String is empty or null");
   }
   else
   {
    MessageBox.Show("String is not empty or null");
   }

  }
 }
}

No comments:

Post a Comment