Search code examples
c#asp.net.net-2.0

Can string.format sequence appear in any order


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);

Solution

  • 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);