C#编译器错误,返回一个不同的值然后预期,在调试时显示正确但返回错误的值

时间:2017-11-15 05:06:24

标签: c# string debugging

在我的C#函数中,我使用动态参数。寻找ID属性,否则采取postid属性。在此代码中,您可以看到它显示1567值,但它返回1614.

我错过了什么,或者我做错了。请有人帮忙。

enter image description here

 public static string URL(dynamic post)
        {
            string link = "";
            int Id = 0;
            if (post?.link != null)
                link = post.link;
            else if (post?.Slug != null)
                link = post.Slug;
            if (post.ID != null)
                Id = post.ID;
            else if (post.postid != null)
                Id = Convert.ToInt32(post.postid);

            return '/' + Id + "-" + link + ".html";
        }

1 个答案:

答案 0 :(得分:7)

'/'是小数点后47位。 1567 + 47 = 1614.请尝试使用"/"。 (注意双引号)