How to use StringBuilder with indexer in C#

1 Answer

0 votes
using System;
using System.Text;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static string SetSB(StringBuilder sb, string[] arr)
        {
            foreach (string s in arr)
            {
                sb.Append(s).AppendLine();
            }

            return sb.ToString();
        }
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("c#");
            sb.AppendLine();
            sb.Append("java").AppendLine();
            sb.Append("c++");

            Console.WriteLine(sb[0]);
            Console.WriteLine(sb[1]);
            Console.WriteLine(sb[3]);
            Console.WriteLine(sb[4]);
        }
    }
}

/*
run:
  
c
#


j

*/

 



answered Jan 15, 2017 by avibootz

Related questions

1 answer 116 views
1 answer 118 views
118 views asked Apr 27, 2017 by avibootz
1 answer 114 views
114 views asked Jan 5, 2017 by avibootz
1 answer 130 views
1 answer 100 views
1 answer 97 views
1 answer 115 views
...