Reputation: 773
I'm working on converting a Java project to C#, but don't know what CharSequence
is corresponding to C# type.
Upvotes: 2
Views: 1893
Reputation: 518
A Java.Lang.String
is an ICharSequence
in C#.
This extension would convert a string
to an ICharSequence
:
public static ICharSequence ToCharSequence(this string text) {
return text == null ? null : new Java.Lang.String(text);
}
Upvotes: 1
Reputation: 6514
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#.
Upvotes: 0
Reputation: 159086
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.
Upvotes: 5
Reputation: 222
CharSequence is an interface that represents a sequence of characters. To hold char array, string (immutable) or StringBuilder classes can be used in c#.
Upvotes: 0