Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# Type Alias/Custom Type

Tags:

c#

types

delphi

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
{
...
}
like image 703
James Barrass Avatar asked Jan 22 '23 19:01

James Barrass


1 Answers

The closest you can get in C# is

using DataEntry = System.Double;

Put this at the top of each file.

like image 198
SLaks Avatar answered Jan 30 '23 08:01

SLaks