As c# doesnt have null character as in c I want to know how to find the length of string without using the length function???

Edited 6 Years Ago by swetz: n/a

Why you want to find the length of string without Length function. One way is use String.ToCharArray() function, then iterate through the loop. Inside loop increment the value of counter variable.

As c# doesnt have null character as in c I want to know how to find the length of string without using the length function???

Most of the time, an electrical engineer is not interested in the internals of an IC.
It is a black box with pins. The function off each pin is what would interest him.
Same for a String. It is an object(black box) with methods(pins)
Lenght is a method so it is simple: use it to get the Lenght of a string.

I agree with the general sentiment here...why are you trying to reinvent the wheel?

Also, just a note to rohand; String.ToCharArray() is redundant...a string is an array of characters :)

class Program
    {
        static void Main(string[] args)
        {
            string test = "test";
            
            //string as char array:

            //iterate through char collection
            foreach (char c in test)
            {
               //do something
            }

            //access elements by index
            Console.WriteLine("Contents of char array : {0}, {1}, {2}, {3}", test[0], test[1], test[2], test[3]);
            Console.ReadKey();
        }

    }
This article has been dead for over six months. Start a new discussion instead.