Why doesn't this string.Format() return string, but dynamic?

后端 未结 3 1317
野性不改
野性不改 2020-12-31 10:12
@{
    ViewBag.Username = \"Charlie Brown\";
    string title1 = string.Format(\"Welcome {0}\", ViewBag.Username);
    var title2 = string.Format(\"Welcome {0}\", Vi         


        
3条回答
  •  时光取名叫无心
    2020-12-31 10:23

    The error message is telling you exactly what's wrong here:

    Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

    title2 is of type dynamic. You need to cast it to string, since you know that's what it is.

提交回复
热议问题