Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the char struct -​- operator defined in .NET?

Tags:

c#

.net

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?

like image 525
Franno Avatar asked May 07 '20 21:05

Franno


People also ask

What is char used for in C#?

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.

What is operator overloading in C#?

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.

Is C# an operator?

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.

What are the methods of the Char struct in C#?

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.

What is the Char structure used to represent Unicode characters?

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.

What is the difference between Char and string in C++?

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.

What is a struct in C?

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.


Video Answer


1 Answers

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.

like image 117
AlesD Avatar answered Oct 23 '22 18:10

AlesD