Find length of a string without the help of length method

Satyapriyanayak
Posted by Satyapriyanayak under C# category on | Points: 40 | Views : 755
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string s1 = "Hello";
int l1 = 0;
try
{
char c;
while (true)
{
c = s1[l1];
l1++;
}
}
catch (IndexOutOfRangeException)
{
}
Console.WriteLine("The length of '{0}' is {1}", s1, l1);
Console.ReadKey();
}

}
}

Comments or Responses

Login to post response