C# String.Format and object as argument
Here is my idea I am reading a string from my .resx file
And here is a sample of such string :"I am writing this from {}"
I wrote a function to pass values to those arguments. I don't know the number of arguments expect开发者_开发技巧ed by the string
public string MyFormattedString (string resourceName, object param=null)
{
string fStr= Resources.ResourceManager.GetString(resourceName);
fStr= string.Format(fStr, param);
return fStr;
}
If I call my function with MyFormattedString ("resourceName", "noWhere"), I do not get what I am expecting What's wrong?
I found a solution to my issue with using params object[] I just discovered
public string MyFormattedString (string resourceName, params object[] param)
{
string fStr= Resources.ResourceManager.GetString(resourceName);
fStr= string.Format(fStr, param);
return fStr;
}
The resource string should be "I am writing this from {0}"
with a numeric position in it.
精彩评论