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 7501859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:40:36+00:00 2026-05-29T20:40:36+00:00

If objects contains null or empty then how to validate or check the condition

  • 0

If objects contains null or empty then how to validate or check the condition for the same?

How to bool check whether object obj is null or Empty

I’ve code as follows:

class Program
{
    static void Main(string[] args)
    {
        object obj = null;

        double d = Convert.ToDouble(string.IsNullOrEmpty(obj.ToString()) ? 0.0 : obj);
        Console.WriteLine(d.ToString());
    }
}

With this code i’m getting NullReference Exception as Object reference not set to an instance of an object.

Pls help.

Here I’m not getting….

How to validate whether that object is null or Empty without converting into .ToString() ??

Is there an approach to check the same??

  • 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-29T20:40:37+00:00Added an answer on May 29, 2026 at 8:40 pm

    The problem that you are running into is that your object is of type, well, object. In order to evaluate it with string.IsNullOrEmpty, you should pass your object in with the cast to (string)

    like so:

    static void Main(string[] args)
    {
        object obj = null;
    
        double d = Convert.ToDouble(string.IsNullOrEmpty((string)obj) ? 0.0 : obj);
        Console.WriteLine(d.ToString());
    }
    

    This will work fine since you are not explicitly calling .ToString on your (nonexistent) object.

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

Sidebar

Related Questions

I just noticed the HashTable objects have a Contains and CotainsKey method, with same
I'm reading JSON data with PHP and that data contains empty objects (like {}
I am working on a Javascript object that contains some YUI objects. The key
I am attempting to validate my object that encapsulates a list of other objects,
Session contains objects whose class definition isn\'t available. Remember to require the classes for
So I have a container(any kind, probably std::map or std::vector) which contains objects of
I have a class that contains a list of objects. What's the best way
I have a Queue that contains a collection of objects, one of these objects
I have a List which contains a list of objects and I want to
I have a vector-like class that contains an array of objects of type T

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.