문제

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