Search code examples
c#stringmethodsfusionchartsaxes

C# Convert a int method into a string method


I'm working with Fusionchart and I need to label the axes. It's working with int but I need a string for the axes

 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;
}

But if I want to change it to string it doesn't work. What's wrong with the code?

 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;
}

Thanks


Solution

  • The only visible error is string yAxisName1 = new string();

    String does not contain constructor with 0 arguments. so make it string yAxisName1 = "";