Can we find the length of string or array of character in c#
can we find the length of string or array of character in c# without using Length property ?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jul 6, 2015, 1:14 AM EDT
Neeraj KumarRank #355 · 7K reputationPosted Jul 5, 2015, 9:58 AM EDT
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Jul 5, 2015, 4:04 PM EDT
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a string to find its lenght");
string ch = Console.ReadLine();
Program p = new Program();
int answer = p.run(ch);
Console.WriteLine(answer);
Console.ReadKey();
}
public int run(string ch)
{
int count = 0;
foreach (char c in ch)
{
count++;
}
return count;
}
}
Rahul PrajapatRank #1,209 · 1.5K reputationPosted Jul 5, 2015, 6:31 PM EDT
int count = 0;
foreach (char c in str)
{
count++;
}
Console.WriteLine(count);
Console.ReadKey();
Rajeesh MenothRank #118 · 18.4K reputationPosted Jul 5, 2015, 9:40 PM EDT
Lalit RaghavRank #1,306 · 1.3K reputationPosted Jul 5, 2015, 10:07 PM EDT
char[] chararr = str.ToCharArray();
Console.WriteLine("String length= " + chararr.Count());
Manoj BhoirRank #599 · 4K reputationPosted Jul 6, 2015, 1:34 AM EDT
MessageBox.Show((array.GetUpperBound(0) + 1).ToString());
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jul 6, 2015, 8:51 PM EDT
Govinda Rajulu YemineniRank #1,517 · 1K reputationPosted Jul 6, 2015, 8:56 PM EDT