I have a string here,

return  string.Format("/abcXYZ990099/abc.aspx?IDA={0}&Name={1}&Teacher={2}",
                ID, Name, Teacher);

Now because of requirement changed I need to get "abcXYZ990099" from database too, Is it possible to do something like this,

return  string.Format("/{3}/abc.aspx?IDA={0}&Name={1}&Teacher={2}",
                    ID, Name, Teacher, NewPropertyValue);
有帮助吗?

解决方案

Yes, you can do that. But I'd re-index the place holders and re-order the params to suit the order they should appear in the returned string, e.g.

return  string.Format("/{0}/abc.aspx?IDA={1}&Name={2}&Teacher={3}",
                    NewPropertyValue, ID, Name, Teacher);

其他提示

This is perfectly OK, format items can appear in any order in the string.

For example, when format strings are stored as localized resources, the format items might be in a culture-specific order. For example, to display a full name, you could use:

String.Format(Resources.FullNameFormatString, firstName, middleName, lastName)

And the display order might depend on the culture, e.g.:

en-US: "{0} {1} {2}"  // First Middle Last

fr-FR: "{2}, {0} {1}" // Last, First Middle

You might even have a localized version that doesn't use one of the format items (e.g. middle name):

"{2), {0}" // Last, First (middle name not used)

Of course, in your example it probably makes more sense to reorder the items, as others have said.

You can do. But change the order, since the code must be understandable.

string.Format("/{0}/abc.aspx?IDA={1}&Name={2}&Teacher={3}",NewPropertyValue, ID, Name, Teacher);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top