Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:30:07+00:00 2026-06-15T19:30:07+00:00

a ?? b If a is not null => returns a . Else (

  • 0

a ?? b

  • If a is not null => returns a.
  • Else (a is null) => returns b.

I want to simulate something like its inverse (AFAIK there is no operator to do this):

  • If a is null => return a.
  • Else (a is not null) => returns b.

The idea is that b would be the result of a function that receives a and needs to avoid null parameters. Like this: a XX fn(a) where XX would be the operator (if it exists).

My only two variants are:

  • a == null ? a : fn(a)
  • a == null ? null : fn(a)

Is there any way to simplify this code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:30:08+00:00Added an answer on June 15, 2026 at 7:30 pm

    Not sure exactly what you’re trying to accomplish? Something like this?

    TResult NullFn<TParam, TResult>(TParam a, Func<TParam, TResult> method)
    {
    if(a == null) return null;
    return method(a);
    }
    
    ...
    
    var result = NullFn(a, a => fn(a))
    

    But the best solution IMHO would be to just have fn return null if it is passed a null value.

    EDIT:

    The method at the top is only an example. You might want to use something like this in a situation where you’ve got a LOT of the same operation over and over again in a specific area and you can’t change fn because it would make is easier to focus on the rest of the code and there’s a chance you might want to alter the null-handling behavior for all your operations at once in the future. (I’m assuming that is the case because you’re asking in the first place.) But I wouldn’t use this across an entire application because it isn’t clear what’s happening if you don’t have the NullFn function right in front of you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables like this: CREATE TABLE table1_lang ( id serial NOT NULL,
Given: CREATE TABLE foo (id BIGINT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id)); I'd like to
create table ImagenesUsuario { idImagen int primary key not null IDENTITY } This doesn't
I have this table (TableA): ( [FieldA] [int] NOT NULL, [FieldB] [int] NOT NULL,
I'm writing a stored procedure and I want to return 0 records when something
create table snippet( id int not null auto_increment, primary key(id), idlanguage int not null,
I need to add a NOT NULL column to an existing (populated) table that
I have a database which has a NOT NULL constraint on a field, and
how can I specify a NOT NULL contraint at the end of my sql
CREATE TABLE `db`.`Complete` ( `CompleteId` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.