为什么我的代码说字符串不能转换为int? [英] why does my code say that strings cannot be converted to int?

查看:114
本文介绍了为什么我的代码说字符串不能转换为int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我还没有将特定的代码片段转换为int或者甚至将其定义为字符串,但它是说我试图将其转换为int。这是我目前的代码,任何帮助将不胜感激



假日h1 =新假期(赫尔,14,8);

假日h2 =新假期(百慕大,2,800);

假日h3 =新假期(洛杉矶,19,1900);

h3 .setcost(2100);

h3.setDuration(12);

假日h4 =新假期();

h4.setcost(370 );

h4.setDestination(平壤);

h4.setDuration(7);

Hi all,
I havent converted the particular piece of code to int or even defined it as strings, yet it is saying that im trying to convert it to int. this is the current code I have and any help would be appreciated

Holiday h1 = new Holiday("Hull", 14, 8);
Holiday h2 = new Holiday("Bermuda", 2, 800);
Holiday h3 = new Holiday("Los Angeles", 19, 1900);
h3.setcost(2100);
h3.setDuration(12);
Holiday h4 = new Holiday();
h4.setcost(370);
h4.setDestination("Pyongyang");
h4.setDuration(7);

推荐答案

检查Holiday构造函数的定义和Holiday.SetDestination方法(取决于错误发生在哪一行)。



在第一种情况下,你需要一个带三个参数的构造函数:string,int,int

在第二种情况下,你需要一个采用字符串的版本,而不是int。
Check the definitions of the Holiday constructor, and the Holiday.SetDestination methods (depending on which line the error occurs on).

In the first case, you need a constructor that takes three parameters: string, int, int
In the second, you need a version that take a string, not an int.


这篇关于为什么我的代码说字符串不能转换为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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