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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:14:48+00:00 2026-06-11T21:14:48+00:00

I am following an example and it has a class that goes like this:

  • 0

I am following an example and it has a class that goes like this:

public class Price
{

private decimal _sellingPrice;
private decimal _rrp;

public Price(decimal RRP, decimal SellingPrice)
{
            _rrp = RRP;
            _sellingPrice = SellingPrice;
}

}

This class is then constructed with values queried from a table using LINQ:

var products = from p in new ShopDataContext().Products                           
                           select new Model.Product
                           {
                               Id = p.ProductId,
                               Name = p.ProductName,
                               Price = new Price(p.RRP, p.SellingPrice)
                           };

On the example this seems to work, however I am getting this error:

Price = new Price(p.RRP, p.SellingPrice)
The best overload method match has some invalid arguments
Argument 1: cannot convert from 'decimal?' to 'decimal' 

The p.RRP and p.SellingPrice values are taken from a table as System.Decimal types and apparently nullable by default hence the exception, tho in the example this seems to run ok, so Why is that?. Is there anything I am missing?. I am experimenting with C# and I know its a strict language by default so there is no option to turn off and make this work in my understanding.

Thank you for your insight.

  • 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-11T21:14:50+00:00Added an answer on June 11, 2026 at 9:14 pm

    The problem is your query is returning a nullable decimal type rather than a decimal type. You need to modify your constructor like this:

    public Price(decimal? RRP, decimal? SellingPrice) {
            _rrp = (decimal) RRP;
            _sellingPrice = (decimal) SellingPrice;
    }
    

    If you want to be thorough in checking for possible errors, you can use one of the techniques described in this article.

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

Sidebar

Related Questions

I was trying following example: class BaseClass { public void methodA(Class<?> cl) { System.out.println(Base.methodA());
To illustrate my question consider the following example: @Entity public class Box implements Serializable
I have a class that only has static members. I would like to register
Assume I have a class like this: public class Foo { public Bar RequiredProperty
I would like to write a JPA entity class that has a one to
I am wondering why in the following example the top and bottom padding has
Is the hook_block has been changed? the following is drupal 6 example i have
Example: Suppose in the following example I want to match strings that do not
I find the following example mildly surprising: >>> class Foo: def blah(self): pass >>>
I have tree like following example, where every leaf is object. [1] |--[2] |

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.