.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Find length of a string without the help of length method of string in C#.

Posted By:satyapriyanayak       Posted Date: February 28, 2014    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

In this Code Snippets we will know how to find length of a string without the help of length method of string.
 

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();
        }
        
    }
}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend