2012-05-16 55 views
1
開頭的c#參數

嘗試傳遞值但未取得進展。如何將值傳遞給以@

場景:具有如下的公共常量字符串。

public const string ImageFile = @"http://xyz.com/scom/{0}?type={1}&wid={2}"; 

然後,我將獲得上述要求的0,1,2所需的相關值。

問題是我如何將值爲0,1,2的值傳遞給上面的const字符串?

我的最終結果應該是這樣的

string mySTring = "http://xyz.com/scom/123?type=jpg&wid=200" 

請建議。

謝謝。

+8

你怎麼知道'string.Format'(即'{0}')的語法而不知道'string.Format'? –

+1

@KirlWoll - 像Console.WriteLine這樣的方法允許合成格式。換句話說,如果不是大多數情況下,'string.format'可以隱式使用。許多開發人員可以使用string.format,甚至不知道它。 http://msdn.microsoft.com/en-us/library/txafckwd.aspx –

+0

我曾經遇到過一個主要的性能問題,因爲有人知道vfprintf的全部內容,但不知道sprintf是否存在... – zmbq

回答

9

使用String.Format

string ActualImageFile = String.Format(ImageFile, param1, param2, param3); 
3
string.Format(@"http://xyz.com/scom/{0}?type={1}&wid={2}", param1, param2, param3); 

應該做的伎倆。