C#类型别名/自定义类型 [英] c# Type Alias/Custom Type
问题描述
我试着去一些Delphi代码转换为C#和我遇到的一个问题...
在德尔福我decalared新型
键入扩展
$的TDATA =阵列b $ b
在那里我可以访问返回此类型与语句如
功能TMyObject.ReadData函数的结果:TDATA ;
开始
:
端;
数据:= MyObject.ReadData;
结果=数据[7] +数据[12]如果我intially宣布
现在单本作阵列
然后我可以改变这一行来改变精度。 (我可能会在短期内做它降低到双击
让任何结果完全匹配C#版本。
所以,问题是我能做到在C#中类似的东西像
类数据:双[]
虽然不完全是这样,因为它不会编译,否则我会做
类DataEntry:双人间
...
公共DataEntry []读取
{
...
}
您可以在类包装双数组并为它提供索引属性。
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
where I can access the result of functions returning this type with statements like
Function TMyObject.ReadData:TData;
begin
...
end;
Data := MyObject.ReadData;
Result = Data[7] + Data[12]
now if I had intially declared this as Array of Single
then I could change this one line to change the precision. (which I may have to do shortly to lower it to Double
so that any results exactly match the c# version.
so the question is can I do something similar in c#? something like
class Data : Double[]
although not exactly like this since it doesn't compile, or would I do
class DataEntry : Double
...
public DataEntry[] Read
{
...
}
You can wrap an array of Double in a class and provide index properties for it.
这篇关于C#类型别名/自定义类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!