Check String Length - CSharp Language Basics

CSharp examples for Language Basics:string

Description

Check String Length

Demo Code

using System;// ww  w .  java2s .  c o  m
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   static void Main(string[] args)
   {
      // Input
      Console.Write("Enter a word: ");
      string word = Console.ReadLine();
      // Determining length
      int wordLength = word.Length;
      // Checking length
      if (wordLength <= 4)
      {
         Console.WriteLine("Word is short (at most 4 characters)");
      }
      else
      {
         Console.WriteLine("Word is long (more than 4 characters)");
      }
   }
}

Result


Related Tutorials