简体   繁体   English

如何为 System.String^ 定义类型别名

[英]How to define a type alias for System.String^

I´m trying to define my own type aliases as follows:我正在尝试定义我自己的类型别名,如下所示:

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

I´m facing problems with the String type.我正面临String类型的问题。 When I try to use the string and pass it as reference:当我尝试使用字符串并将其作为参考传递时:

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

I cannot compile:我无法编译:

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

On the other hand, If I define:另一方面,如果我定义:

using PrjString = System.String^; 

It does not compile as well:它也不能编译:

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

Is there a way to define a type alias for System.String^ ?有没有办法为System.String^定义类型别名?

The ^ notation is not valid syntax in c#. ^符号在 c# 中不是有效的语法。 To pass by reference, use the ref keyword:要通过引用传递,请使用ref关键字:

using PrjString = System.String;

PrjString name;
GetName(ref name); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM