2016-09-13 28 views
-4

I'm一個類型別名試圖定義自己的類型別名如下:如何定義System.String^

using PrjString = System.String; 
using PrjInt = System.Int32; 
using PrjFloat = System.Single; 
using PrjDateTime = System.DateTime; 

I'm與String型面臨的問題。當我嘗試使用字符串,並把它作爲參考:

PrjString^ name; 
GetName(name); // Receives name as reference and return the gathered name 

我不能編譯:

PrjString ^name: error CS0118: `string` is a `type` but is used like a `variable` 

在另一方面,如果我定義:

using PrjString = System.String^; 

它不編譯以及:

using PrjString = System.String^: error CS1002: ; expected 

有沒有辦法爲System.String^定義一個類型別名?

+7

爲什麼在地球上您想要別名基本類型? – DavidG

+0

''^是不是在C# –

+0

這是不完全相關的問題的問題,而是i'm建立一個跨環境的SDK,我需要所有類型的被命名爲平臺之間的同正確的語法.... – Mendes

回答

1

^符號是不是在C#有效的語法。要通過參考,請使用ref關鍵字:

using PrjString = System.String; 

PrjString name; 
GetName(ref name); 
+0

作用似乎我無法通過String's作爲參考.... [從這裏](http://stackoverflow.com/questions/3929333/c-cli-why-cant-i-pass-strings-by-reference) – Mendes

+0

是的,你可以。你鏈接到一個C++的答案 – KSib

相關問題