When I look at the documentation for the .NET Char Struct (here: https://learn.microsoft.com/en-us/dotnet/api/system.char), I can see the usual properties, methods, etc., as for any other Type defined in the .NET Framework.
I know that the char struct has a --
operator defined for it as I can do the following:
char current = 'b';
current--; // current now holds the value a.
When looking at the Microsoft documentation I would expect to see an operator overloading definition which would look something like :
public static Char operator --(char character)
{
}
The problem is I don't see anything like that neither it is said which operator is overloaded for the type. For the char Type example, char has an operator overload for -- but not for - and I think it would be good to know where all the overloaded operators are documented rather than do trials and errors.
So my questions are: How can one know which operator is defined for which type? Is it somewhere else in the .NET API documentation that I have missed?
Keywords are the words in a language that are used for some internal process or represent some predefined actions. char is a keyword that is used to declare a variable which store a character value from the range of +U0000 to U+FFFF. It is an alias of System.
Operator overloading gives the ability to use the same operator to do various operations. It provides additional capabilities to C# operators when they are applied to user-defined data types.
The is operator is used to check if the run-time type of an object is compatible with the given type or not. It returns true if the given object is of the same type otherwise, return false. It also returns false for null objects.
The Char Struct in C# represents a character as a UTF-16 code unit. Here are some of the methods − Let us see an example to implement the Char.IsSymbol () method. The Char.IsSymbol () method in C# is indicated whether the character at the specified position in a specified string is categorized as a symbol character.
The .NET Framework uses the Char structure to represent a Unicode character. The Unicode Standard identifies each Unicode character with a unique 21-bit scalar number called a code point, and defines the UTF-16 encoding form that specifies how a code point is encoded into a sequence of one or more 16-bit values.
The char type supports comparison, equality, increment, and decrement operators. Moreover, for char operands, arithmetic and bitwise logical operators perform an operation on the corresponding character codes and produce the result of the int type. The string type represents text as a sequence of char values.
The struct (structure) is like a class in C# that is used to store data. However, unlike classes, a struct is a value type. Suppose we want to store the name and age of a person. We can create two variables: name and age and store value.
What you are looking for is described in the C# Language Specification. The Integral Types topic lists the char type as being one of the integral types.
The char type represents unsigned 16-bit integers with values between 0 and 65535. The set of possible values for the char type corresponds to the Unicode character set. Although char has the same representation as ushort, not all operations permitted on one type are permitted on the other.
Regarding the operators you need to look at the Prefix increment and decrement operators topic in he C# language specification.
Predefined ++ and -- operators exist for the following types: sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, and any enum type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With