2015-10-18 18 views
0
public string LookAtln(Player p, string thingId, string containerId) 
    { 
     //I'm not sure using a formatter is good or not 
     string f = String.Format ("Look at thingId in containerId"); 
     ...... 
    } 

,用戶將輸入像這樣的:是否有可能爲該方法定義字符串格式化?

  • 看看筆袋
  • 看看袋庫存
  • 看看筆
  • 看看袋子

筆是一個項目,包都是項目和集裝箱,庫存容器。而且該方法將返回一個字符串來形容他們。

我在C#中的新的學習者,我甚至不能確定它是正確的在這裏或不使用格式,如果有人對這個方法好主意,非常感謝!

回答

1

在C#6,以後你可以用串插使用它:

string f = $"Look at {thingId} in {containerId}";  

或者,如果你的目標是舊版本,

string f = String.Format ("Look at {0} in {1}", thingId, containerId); 
相關問題