【发布时间】:2015-11-28 23:41:06
【问题描述】:
所以,我知道有人用这个名字发布过类似的帖子,但其他帖子并没有帮助我找到解决问题的方法。 我有 1 个表格和 4 个带方法的类,在名为 Costs 的类中出现问题,得到所有其他 3 个类并放入他。 我将在这里发布四个类。
头等舱 - 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
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(问题出在哪里)
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)
{
}
}
}
如果你们能帮助我,我会感谢的。问题是不是所有的代码路径都返回一个值。
【问题讨论】:
-
如何阅读有关此类微不足道的文档?
-
“并非所有代码路径都返回值”是比较明显的编译器错误之一...
-
如果这些话对您没有帮助,请务必记下数字 CS0161(CS 表示 C# 编译器)。 MSDN 应该能够告诉您有关 C# 错误的信息。如果您使用 IDE,它甚至可能会为您查找(尝试 F1)。
-
好吧,对不起,伙计们,我知道这个问题有点菜鸟,哈哈,我一开始不明白,但这个错误永远不会再发生了。所以谢谢你的帮助(或不是 xxbbcc 和 Leigh Shepperson)。