C# Return Calculated Field in Model

I want ExtendedPrice to be calculated from values of two fields below.  I am getting below errors:

"A field initializer cannot reference the non-static field, method, or property 'MyApp.Models.ItemsModel.UnitPrice.get"
"A field initializer cannot reference the non-static field, method, or property 'MyApp.Models.ItemsModel.Total.get"

 public class ItemsModel
        public string CustomerName { get; set; }
        public string PO { get; set; }
        public string DateOrder { get; set; }
        public string Total { get; set; }
        public string UnitPrice { get; set; }
        public string extendedPrice = Convert.ToDouble(UnitPrice) * Convert.ToDouble(Total);

Open in new window

How do I return a calculated field in the model.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
you need to use something like:
public string extendedPrice { get {return  (Convert.ToDouble(UnitPrice) * Convert.ToDouble(Total)).ToString("#,##0.00"); } }

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Florian LenschowCommented:
You could also write an init function that computes extendedPrice and call this function in the objects constructor.
CipherISAuthor Commented:
@Eric - Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.