Object Initializer Indexer - CSharp Custom Type

CSharp examples for Custom Type:Indexer

Description

Object Initializer Indexer

Demo Code

using System;/*from   w ww .java 2 s .com*/
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class ObjectInitializerIndexer
{
   static void Main()
   {
      string text = "This text needs truncating";
      StringBuilder builder = new StringBuilder(text)
      {
         Length = 10,
         [9] = '\u2026'
      };
      Console.OutputEncoding = Encoding.UTF8;
      Console.WriteLine(builder);
   }
}

Result


Related Tutorials