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???

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???

char NullChar = char(0)

should return the null character value.

If you don't mind then can you please explain in detail ?

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

    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.