Monday, February 27, 2017

How to use C# string Length

using System;
using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
            string str = null;
            str = "This is a Test";
            MessageBox.Show(str.Length.ToString()); 
        }
    }
}


When you execute this C# source code you will get 14 in the messagebox. 

No comments:

Post a Comment