Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a new operator in c#?

Tags:

operators

c#

.net

I know you can overload an existing operator. I want to know if it is possible to create a new operator. Here's my scenario.

I want this:

var x = (y < z) ? y : z; 

To be equivalent to this:

var x = y <? z; 

In other words, I would like to create my own <? operator.

like image 391
Aaron Palmer Avatar asked Jun 24 '09 18:06

Aaron Palmer


People also ask

Is there a new operator in C?

C uses the malloc() and calloc() function to allocate memory dynamically at run time and uses a free() function to free dynamically allocated memory. C++ supports these functions and also has two operators new and delete, that perform the task of allocating and freeing the memory in a better and easier way.

Can we overload new operator?

New and Delete operators can be overloaded globally or they can be overloaded for specific classes. If these operators are overloaded using member function for a class, it means that these operators are overloaded only for that specific class.

Is there any new operator in C++ over C?

The new operator denotes a request for memory allocation on the Heap. If sufficient memory is available, new operator initializes the memory and returns the address of the newly allocated and initialized memory to the pointer variable.


1 Answers

No, it is not possible. You would need to create a method instead

like image 104
AgileJon Avatar answered Nov 09 '22 14:11

AgileJon