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

  • Home
  • SEARCH
  • 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 427295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:33:53+00:00 2026-05-12T19:33:53+00:00

Fails: object o = ((1==2) ? 1 : test); Succeeds: object o; if (1

  • 0

Fails:

object o = ((1==2) ? 1 : "test");

Succeeds:

object o;
if (1 == 2)
{
    o = 1;
}
else
{
    o = "test";
}

The error in the first statement is:

Type of conditional expression cannot be determined because there is no implicit conversion between ‘int’ and ‘string’.

Why does there need to be though, I’m assigning those values to a variable of type object.

Edit: The example above is trivial, yes, but there are examples where this would be quite helpful:

int? subscriptionID; // comes in as a parameter

EntityParameter p1 = new EntityParameter("SubscriptionID", DbType.Int32)
{
    Value = ((subscriptionID == null) ? DBNull.Value : subscriptionID),
}
  • 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-05-12T19:33:53+00:00Added an answer on May 12, 2026 at 7:33 pm

    use:

    object o = ((1==2) ? (object)1 : "test");
    

    The issue is that the return type of the conditional operator cannot be un-ambiguously determined. That is to say, between int and string, there is no best choice. The compiler will always use the type of the true expression, and implicitly cast the false expression if necessary.

    Edit:
    In you second example:

    int? subscriptionID; // comes in as a parameter
    
    EntityParameter p1 = new EntityParameter("SubscriptionID", DbType.Int32)
    {
        Value = subscriptionID.HasValue ? (object)subscriptionID : DBNull.Value,
    }
    

    PS:
    That is not called the ‘ternary operator.’ It is a ternary operator, but it is called the ‘conditional operator.’

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

Sidebar

Related Questions

The following unit test fails, I make changes to an object that I've retrieved
The following F# code fails because Type.DefaultBinder does not want to bind to the
I'm new in rspec, write rspec-test for View and there's a problem: test fails
object_getIvar(id object, Ivar ivar) reads the values of iVArs properly but fails on a
I'm implementing a TryParse(string s, Out object result) method. If the parse fails, I
This fails with an ObjectDisposedException when trying to assert: [Test] public void Resolve_SingletonAndDisposeChildContainer_ShouldNotDisposeSingleton() {
This fails on VS2010 RC LINQ-to-SQL with the InvalidOperationException Stored procedures cannot be used
Having a weird problem with Python's unittest and PyMongo. The test randomly succeeds or
object Test extends Application { // compiles: Map[Int, Value]( 0 -> KnownType(classOf[Object]), 1 ->
Can one write something like: class Test(object): def _decorator(self, foo): foo() @self._decorator def bar(self):

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.