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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:30:02+00:00 2026-06-07T12:30:02+00:00

selectedItem has two fields: int? _cost string _serialNumber In this example, _cost and _serialNumber

  • 0

selectedItem has two fields:

  • int? _cost
  • string _serialNumber

In this example, _cost and _serialNumber of selectedItem are BOTH null. I am reading through the fields of selectedItem via their properties, and filling in textboxes with their values, when…

TextBox1.Text = selectedItem.Cost.ToString(); //no error
TextBox2.Text = selectedItem.SerialNumber.ToString(); //error

I understand that SerialNumber.ToString() is redundant (because it is already a string), but I don’t understand why this causes this exception:

Nullable object must have a value.

  • int? _cost is nullable, and does not have a value, yet it does not give me the exception.
  • string _serialNumber is nullable, and does not have a value, yet it does give me the exception.

This question touches on it, the guy is essentially asking the same thing, but there is no designated answer, and it also doesn’t explain why a nullable int? For example, can I use .ToString() on a nullable int but not on a null string?

  • 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-07T12:30:03+00:00Added an answer on June 7, 2026 at 12:30 pm

    Because string type’s null really points to nothing, there isn’t any object in memory.
    But int? type(nullable) even with value set to null still points to some object.
    If you read Jeffrey Richter’s “CLR via C#” you’ll find out that nullable type are just facade classes for common types with some incapsulated logics in order to make work with DB null more convenient.

    Check msdn to learn about nullable types.

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

Sidebar

Related Questions

I made a class called SpecializationBean which has two private fields: private ArrayList<SelectItem> specializationItems=
QComboBox has two signals, both called currentIndexChanged ; one passes the index of the
I have a project that has mainly two objects, both inheriting from a base.
I have a ListView which has bound data, and two additional bindings like this:
I have a ComboBox that has the SelectedItem bound to the ViewModel. <ComboBox SelectedItem={Binding
I am having an issue with two-way binding the SelectedItem of the ListPicker In
I have two very similar .aspx pages. Both of them contain a DropDownList control.
System.Windows.Forms.ComboBox has two different events that the programmer can handle: SelectionChangeCommitted - event fires
I have a form that has two buttons, textbox, listbox, and a combobox. The
I'm using MVVM, in case it makes a difference. My MainWindowViewModel has two DependencyProperties,

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.