C# 将一个int方法转换成一个字符串方法
C# Convert a int method into a string method
我正在使用 Fusionchart,我需要标记坐标轴。
它与 int 一起使用,但我需要一个用于轴的字符串
public int GetyAxisName(int chartId)
{
Chart_AttributeModel chart_AttributeModel = new Chart_AttributeModel();
List<Chart_Attribute> attributes = chart_AttributeModel.GetChart_AttributeByChart(chartId);
AttributeModel attributeModel = new AttributeModel();
int yAxisName = new int();
foreach (Chart_Attribute ca in attributes)
{
Attribute a = attributeModel.GetAttribute(ca.AID);
if (a.Name == "yAxisName")
{
yAxisName = Convert.ToInt32(ca.Value);
}
}
return yAxisName;
}
但是如果我想把它改成字符串就不行了。
代码有什么问题?
public string GetyAxisName(int chartId)
{
Chart_AttributeModel chart_AttributeModel = new Chart_AttributeModel();
List<Chart_Attribute> attributes = chart_AttributeModel.GetChart_AttributeByChart(chartId);
AttributeModel attributeModel = new AttributeModel();
string yAxisName = new string();
foreach (Chart_Attribute ca in attributes)
{
Attribute a = attributeModel.GetAttribute(ca.AID);
if (a.Name == "yAxisName")
{
yAxisName = Convert.ToString(ca.Value);
}
}
return yAxisName;
}
谢谢
唯一可见的错误是 string yAxisName1 = new string();
字符串不包含参数为 0 的构造函数。所以让它 string yAxisName1 = "";
我正在使用 Fusionchart,我需要标记坐标轴。 它与 int 一起使用,但我需要一个用于轴的字符串
public int GetyAxisName(int chartId)
{
Chart_AttributeModel chart_AttributeModel = new Chart_AttributeModel();
List<Chart_Attribute> attributes = chart_AttributeModel.GetChart_AttributeByChart(chartId);
AttributeModel attributeModel = new AttributeModel();
int yAxisName = new int();
foreach (Chart_Attribute ca in attributes)
{
Attribute a = attributeModel.GetAttribute(ca.AID);
if (a.Name == "yAxisName")
{
yAxisName = Convert.ToInt32(ca.Value);
}
}
return yAxisName;
}
但是如果我想把它改成字符串就不行了。 代码有什么问题?
public string GetyAxisName(int chartId)
{
Chart_AttributeModel chart_AttributeModel = new Chart_AttributeModel();
List<Chart_Attribute> attributes = chart_AttributeModel.GetChart_AttributeByChart(chartId);
AttributeModel attributeModel = new AttributeModel();
string yAxisName = new string();
foreach (Chart_Attribute ca in attributes)
{
Attribute a = attributeModel.GetAttribute(ca.AID);
if (a.Name == "yAxisName")
{
yAxisName = Convert.ToString(ca.Value);
}
}
return yAxisName;
}
谢谢
唯一可见的错误是 string yAxisName1 = new string();
字符串不包含参数为 0 的构造函数。所以让它 string yAxisName1 = "";