C#错误

编程入门 行业动态 更新时间:2024-10-26 22:16:39
本文介绍了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#错误

本文发布于:2023-11-10 01:19:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573966.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!