小编Jas*_*L95的帖子

C#中的数学错误

我目前正在用C#编写Shop程序的代码.我对C#比较陌生,我很难让数学在下面的代码中工作:

//Add Basket
public void addBasket()
{
   //Add up the total of individual items
   double total = 0;
   if (shoppingCart.Count() == 0)
   {
      Console.WriteLine("ERROR - Basket is Empty");
   }
   else
   {
      foreach (Products tmp in shoppingCart)
      {
         total = (tmp.Price * tmp.BoughtStock);
         Console.WriteLine("The cost of the individual item  is: " + "\t" +total);
      }
   }
   //Calculate the products together
   double itemTotal = 0;
   if (shoppingCart.Count() == 0)
   {
      Console.WriteLine("ERROR - Basket is Empty");
   }
   else
   {
      foreach (Products tmp in …
Run Code Online (Sandbox Code Playgroud)

c# math

3
推荐指数
1
解决办法
259
查看次数

"并非所有代码路径都返回值"C#

您好我目前正在Windows Phone/C#上编写petshop应用程序的婴儿阶段.我在下面的课程中设置了我的通用列表,并且能够使用给定的字段(姓名,年龄,品种和类型)将宠物添加到商店.我相信的问题在于我正在制作一个显示方法(在下面称为Mainpage.xaml.cs的另一个页面中,名为Mainpage.xaml.cs),名为DisplayShop(),我正在阅读3个字符串和一个int,我相信它与我的DisplayShop()方法是一个字符串这一事实有关,虽然我试图通过将age字段转换为Display()方法中的字符串来解决问题,尽管这并没有解决问题.

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink; 
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assignment_1
{
    public class Shop
    {
        private string name;
        private int age;
        private string breed;
        private string type;

        public Shop(string Name, int Age, string breed, string Type)
        {
            this.Name = name;
            this.Age = age;
            this.breed = breed;
            this.Type = type;
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set …
Run Code Online (Sandbox Code Playgroud)

c# windows xaml

0
推荐指数
1
解决办法
274
查看次数

标签 统计

c# ×2

math ×1

windows ×1

xaml ×1