C#错误-并非所有代码路径都返回值 [英] C# error - Not all code paths return value

查看:45
本文介绍了C#错误-并非所有代码路径都返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道其他人也有这样的名字,但是其他的帖子并没有帮助我找到解决问题的方法.我有1个Form和4个带方法的类,并且在名为Costs的类中遇到了问题,将所有其他3个类都放入了他.我将在这里发布这四个课程.

So guys I know that have another posts like this with this name,but the other posts didn't help me find some solution for my problem. I have 1 Form and 4 Class with methods,and It's getting problem in the Class called Costs,that get's all the other 3 Class and put in him. I will post here the four classes.

头等舱-Alimentaçao

First Class - Alimentaçao

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Projeto_CustosViagem
{
    class Alimentaçao
    {
        private String descriçao { get; set; }
        private double valorTotal { get; set; }
        private String nomeRestaurante { get; set; }

        public Alimentaçao()
        {
            valorTotal = 0;
        }

        public void calcularDespesa(int qtdeRef)
        {
            valorTotal = qtdeRef * 18;
        }

        public void listarDespesa()
        {
            MessageBox.Show("Descrição : " + descriçao + "Valor Total = " + valorTotal + "Nome do Restaurante : " + nomeRestaurante);
        }


    }
}

第二类-运输

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Projeto_CustosViagem
{
    class Transporte
    {
        private double kmPercorrida { get; set; }
        private double valorPedagios { get; set; }
        private double valorTotal { get; set; }


        public Transporte() {
            kmPercorrida = 0;
            valorPedagios = 0;
            valorTotal = 0;
        }

        public void calcularDespesa()
        {
            valorTotal = (kmPercorrida * 8);
        }


        public void listarDespesa()
        {
            MessageBox.Show("Km Percorridos : " + kmPercorrida + "Valor dos Pedagios : " + valorPedagios + "Valor Total : " + valorTotal);
        }

    }


}

第三堂课-Hospedagem

Third Class - Hospedagem

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Projeto_CustosViagem
{
    class Hospedagem
    {
        private String nomeHotel { get; set; }
        private double valorDiaria { get; set; }
        private int qtdeDiarias { get; set; }
        private double valorTotal { get; set; }


        public Hospedagem()
        {
            valorDiaria = 0;
            qtdeDiarias = 0;
            valorTotal = 0;
        }


        public void calcularDespesa()
        {
            valorTotal = (qtdeDiarias * valorDiaria);
        }

        public void listarDespesa()
        {
            MessageBox.Show("Nome do Hotel : " + nomeHotel + "Valor da Diária : " + valorDiaria + "Quantidade de Diárias : " + qtdeDiarias + "Valor total : " + valorTotal);
        }
    }
}

四堂课-Custos(问题出在哪里)

Four Class - Custos(where are the problem)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Projeto_CustosViagem
{
    class Custos
    {
        public double totalViagem(Alimentaçao A, Transporte T, Hospedagem H)
        {

        }
    }
}

如果你们能帮助我,我会谢谢.问题指出,并非所有代码路径都返回一个值.

If you guys can help me,I will thanks.The problem says that not all code paths return a value.

推荐答案

您的方法"totalViagem"不返回任何内容,您已将其返回类型设置为double,但不返回任何内容,这正是问题所在

your method "totalViagem" doesnt return anything, you have set its return type as double but it returns nothing, therin lies your problem

这篇关于C#错误-并非所有代码路径都返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆