我還是比較新的c#編程,所以我試圖做一個類方法。 但它不會工作。c#將一個字符串轉換爲2個雙打
那麼我想要做什麼: 我得到了一個字符串,其名稱中有一個var。 x和y數字。 例如字符串將如下所示:「x02y42」
所以我想在我的應用程序(wpf窗口)中有一個函數,我可以將該字符串發送回來,並獲取2個雙精度,如下所示:「double = 02 「和」double = 42「(所以不是字符串)。
所以我做了一個新的類, 這個類中我有此代碼:
public double x,y(string parm)
{
//input shall be: string s = x12y04;
//inp s looks like x12y04
//splut the string on the Y (so this tech should also work for x89232y329)
//so this will create res[0] that is x89232 and an res[1] that is 329
string[] res = parm.Split(new string[] { "y" }, StringSplitOptions.RemoveEmptyEntries);
//now for the x in res[0], we replace it for a 0 so it are all numbers
string resx = res[0].Replace("x", "0");
//now we will get the strings to doubles so we can really start using them.
double x = double.Parse(resx);
double y = double.Parse(res[1]);
//get the values back
return x, y;
}
現在(OFC)沒有奏效。但是如上所述,我對c#仍然很陌生。 那麼我在這裏做錯了什麼? 我可以把它放在1個功能嗎? 因此,在我的應用程序中,我可以以某種方式調用它?
這種方法甚至不能編譯... sintax是錯的 – giammin 2012-01-11 00:00:25