String Array in C# Interview Questions and Answers

String Array in C# Interview Questions and Answers

 

Below is the frequently asked top c# interview question on string arrays for freshers and experience. below is the list. in below list only given on string examples, not integer example.

if you want on integer example, please go to "C# Logical Interview Questions And Answers"

  • Reverse the given String
  • Check given string is palindrome or not
  • Write a program for replacing the "," with " "spaces
  • Write a program to replace the "," with "?" spaces
  • Write a program to count the number of Vowels and Consonants in the given array
  • Write the program to print the only vowels count and consonants count(remove duplicates)
  • Reverse the words in the given string
  • Write the program from Lowercase to Uppercase
  • write the program from Uppercase to Lowercase 

Reverse the given String

using System;

using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            string s = "murali";

            char[] ch = s.ToCharArray();

            int size = s.Length;

            string rev = null;

            for (int i= size-1 ;i>=0 ;i--) {

                rev = rev + ch[i];

            }

            Console.WriteLine("The Reverse string "+rev);

            Console.ReadLine();

        }

    }

}        

Check given string is palindrome or not


using System;

using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            string s = "madam";

            int size = s.Length;

            char[] ch = s.ToCharArray();

            string rev = null;

            for (int i=size-1; i>=0 ; i--)

            {

                rev= rev+ch[i];

            }

            if (s == rev)

            {

          Console.WriteLine("give string is palindrome -->" + rev + " s= " + s);

            }

            else

            {

    Console.WriteLine("give string is not palindrome -->" + rev + " s= " + s);

            }

            Console.ReadLine();

        }

    }

}


Write a program for replacing the "," with " "spaces


 using System;

using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            string s = "siva,murali,sathqi,bhavani,rani,valli,meena";

            int size = s.Length;

            char[] ch = s.ToCharArray();

            for (int i=size-1; i>=0 ; i--)

            {

                if (ch[i]== ',')

                {

                    ch[i] = ' ';

                }

            }

            for (int i = 0; i<=size-1;i++)

            {

                Console.Write(ch[i]);

            }

           

            Console.ReadLine();

        }

    }

}       

Write a program to replace the "," with "?" spaces


using System;

using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            string s = "siva,murali,sathqi,bhavani,rani,valli,meena";

            int size = s.Length;

            char[] ch = s.ToCharArray();

            for (int i=size-1; i>=0 ; i--)

            {

                if (ch[i]== ',')

                {

                    ch[i] = '/';

                }

            }

            for (int i = 0; i<=size-1;i++)

            {

                Console.Write(ch[i]);

            }

           

            Console.ReadLine();

        }

    }

}


Write a program to count the number of Vowels and Consonants in the given array


 

using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            string s = "muralii";

            int size = s.Length;

            char[] ch = s.ToCharArray();

            int vcount = 0;

            int ccount = 0;

 

            for (int i=0;i<=size-1;i++)

            {

                      if (ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' || ch[i] == 'o' || ch[i] == 'u')

                {

                    vcount++;

                }

                else

                {

                    ccount++;

                }

            }

            Console.WriteLine("vowels == "+vcount);

            Console.WriteLine("consonents =="+ccount);

 

            Console.ReadLine();

        }

    }

}



Write the program to print the only vowels count and consonants count(remove duplicates)



using System;

using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            string s = "aaeeemkyt";

            int size = s.Length;

            char[] ch = s.ToCharArray();

            int vcount = 0;

            int ccount = 0;

 

            for (int i=0;i<=size-1;i++)

            {

                for (int j=i+1;j<=size-1;j++)

                {

                    if (ch[i]==ch[j])

                    {

                        ch[i] = ' ';

                    }

              

                }

            }

            for (int i = 0; i <= size - 1; i++)

            {

                if (ch[i]!=' ')

                {

                    if (ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' || ch[i] == 'o' || ch[i] == 'u')

                    {

                        vcount++;

                    }

                    else

                    {

                        ccount++;

                    }

                } }

            Console.WriteLine("vowels == "+vcount);

            Console.WriteLine("consonents =="+ccount);

 

            Console.ReadLine();

        }

    }

}


Reverse the words in the given string



using System;

using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            string s = "all blogs are not ecommerce sites";

            int size = s.Length;

            char[] ch = s.ToCharArray();

            // int strinwordcount = 0;

            string[] sarray = new string[6];

            int x = 0;

            for (int i=0;i<=size-1;i++)

            {

                if (ch[i] != ' ')

                {

                    sarray[x] = sarray[x] + ch[i];

                }

                else

                {

                    x++;

                }

            }

            for (int i = 5; i >= 0; i--)

            {

                Console.Write(" " +sarray[i]);

             }

            Console.ReadLine();

        }

    }

}





Previous Post Next Post