c# Type Alias/Custom Type

前端 未结 4 912
我在风中等你
我在风中等你 2021-01-19 05:09

Im trying to convert some Delphi code to c# and I\'ve come across a problem...

In Delphi I\'ve decalared a new type

Type TData = Array of Extended


        
相关标签:
4条回答
  • 2021-01-19 05:50

    It sounds like you want something similar to a C/C++ typedef, which unfortunately I don't think is supported in C#. You can make local alias within a single source file (see below), but the alias won't be visible anywhere else.

    To create a local alias, add this at the top of your source file:

    using Data = System.Double;
    
    0 讨论(0)
  • 2021-01-19 05:51

    No, C# has no direct way of doing that.

    You could however wrap that array (and all or most code that uses it) in a generic class:

    class MyClass<T>
    {
       private T[] Mydata;
    
    }
    
    0 讨论(0)
  • 2021-01-19 05:56

    You can wrap an array of Double in a class and provide index properties for it.

    0 讨论(0)
  • 2021-01-19 05:59

    The closest you can get in C# is

    using DataEntry = System.Double;
    

    Put this at the top of each file.

    0 讨论(0)
提交回复
热议问题