C#设置字符串值";而不打印

本文关键字:打印 quot 设置 字符串 | 更新日期: 2023-09-27 18:30:07

全面披露:这是一项家庭作业。我不是在寻求施舍,只是因为我陷入困境而寻求指导。

我正在尝试将month和day(均为int)转换为"month/day"的字符串表示。这就是我到目前为止所拥有的。

我想不出的是如何在月和日之间返回带"/"的日期。

    public string toString()  
    {
        string month = myMonth.ToString();
        string day = myDay.ToString();
        string date = month "/" day; // I know this won't work. I just wanted to give a visual of what I want the final result to look like.
        /// so today would be ' 11/11 ' tomorrow ' 11/12 '
        return date;
    }

注意:此方法不打印结果,只创建结果。

C#设置字符串值";而不打印

Mihai是正确的,但您也可以这样做:-

string data = string.Format("{0}/{1}",month,day);

在我看来,这看起来更好

public string toString()  
    {
        return myMonth + "/" + myDay;
    }

    public string toString()  
    {
        return string.format("{0}/{1}",myMonth,myDay);
    }