serdar
serdar

Reputation: 1618

Can I create an alternative for not operator `!`

I think ! is a very small sign to make the condition having negative meaning. Can I use some alternative for that or create my own keyword (I would like to use not, but if it is reserved keyword anything is ok.).

Upvotes: 1

Views: 164

Answers (2)

y.selivonchyk
y.selivonchyk

Reputation: 9900

I don`t think it would be a good approach but i can suggest adding extension method to bool type. It would look like this

public static class BoolExtentions
{
    public static bool Not(this bool self)
    {
        return !self;
    }
}

Upvotes: 0

jsalonen
jsalonen

Reputation: 30481

Use !. Its the conventional and simplest way to perform logical negation in C#.

You could obviously do whatever you like for yourself, but:

  1. other libraries/code still use !

  2. if some other people run across your code they will get confused (and probably still use ! when editing your code).

Upvotes: 5

Related Questions