1

I'm working on converting a Java project to C#, but don't know what CharSequence is corresponding to C# type.

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
superche
  • 753
  • 3
  • 9
  • 21
  • What do you need from `CharSequence` you can't get from `string` or what kind of parameter do you want to support/accept in your methods/code? – Progman Sep 10 '18 at 20:50
  • You want a similar interface in C# for `CharSequence` interface in Java? – Bouke Sep 10 '18 at 21:00

3 Answers3

3

There is no direct equivalent in c#. Use string instead.

The Java CharSequence is a simple abstraction, that allows methods with simple needs to accept a String, CharBuffer, Segment, StringBuffer, or StringBuilder without having to convert the others to String first.

It allows minor performance improvement in Java for some API methods.

Andreas
  • 154,647
  • 11
  • 152
  • 247
0

CharSequence is an interface that represents a sequence of characters. To hold char array, string (immutable) or StringBuilder classes can be used in c#.

Django
  • 222
  • 1
  • 5
0

A CharSequence is a sequence of characters which is implemented by StringBuilder, StringBuffer, String.

The closest to CharSequence in C# is:

char[] charArr = sentence.ToCharArray();

Strings are immutable in Java and C#. There is no mutable CharSequence in C#.

A CharSequence is basically a bridge between String and StringBuilder in Java.

C# being the best language doesnt suffer from identity crisis.

You are better off using String or StringBuilder in C#.

Gauravsa
  • 6,330
  • 2
  • 21
  • 30