定义我自己的数据类型 [英] Define my own data type

查看:111
本文介绍了定义我自己的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,


之前在Pascal,C ++等中可以定义我们的自定义数据类型

或重新定义现有类型,例如Turbo Pascal我们可以假设

shortint是int并且像所有这些变量一样使用所有对shortint的引用

成为int。


我们怎样才能在C#中定义自己的用户数据类型?


只是D.

All,

It was possible before in Pascal, C++, etc. to define our custom data type
or redefine the existing type, like in Turbo Pascal we could assume that
shortint is int and use all references to shortint like all these variables
became int.

How can we define our own user data type in C# is we can?

Just D.

推荐答案

>之前在Pascal,C ++等中可以定义我们的自定义数据类型
> It was possible before in Pascal, C++, etc. to define our custom data type
或重新定义现有类型,就像在Turbo Pascal中我们可以假设
shortint是int并使用所有引用像所有这些变量变成int的短路。

我们怎样才能在C#中定义自己的用户数据类型?
or redefine the existing type, like in Turbo Pascal we could assume that
shortint is int and use all references to shortint like all these
variables became int.

How can we define our own user data type in C# is we can?




你能引用一个C ++示例(如果我理解你,可能会使用宏或者typedef)。注意BTW,类*是*自定义数据类型。



Can you cite a C++ example (probably using a macro or typedef if I
understand you). Note BTW that a class *is* a custom data type.


Just D写道:
之前可能在Pascal,C ++等中。定义我们的自定义数据类型
或重新定义现有类型,比如在Turbo Pascal中,我们可以假设
shortint是int并使用shortint的所有引用,就像所有这些变量一样,变成了int。

我们如何在C#中定义自己的用户数据类型?
It was possible before in Pascal, C++, etc. to define our custom data type
or redefine the existing type, like in Turbo Pascal we could assume that
shortint is int and use all references to shortint like all these variables
became int.

How can we define our own user data type in C# is we can?




一般来说,在C#中定义一个新的类_is_一种新类型。


但是,如果你想要定义一个别名,那么对于

现有数据类型,例如,代码中的所有位置

表示


短x;


等使用int类型而不是short类型那是写的

那里,然后不,你不能在C#中做到这一点。此外,它是一个很棒的

功能(或非功能),你不能这样做。在20年的C $ / $
编程中,我看到这个功能(ab)只使用了一次,我花了一个小时的时间盯着代码和调试,想知道为什么它正在行动

so#



In general terms, defining a new class in C# _is_ defining a new type.

If, however, you mean that you want to define an "alias" for an
existing data type, so that, for example, all places in your code that
say

short x;

and suchlike use the int type instead of the "short" that is written
there, then no, you cannot do that in C#. Furthermore, it''s a great
feature (or un-feature) that you can''t do that. In 20 years of C
programming I saw this feature (ab)used only once, and it took me an
hour of staring at the code and debugging, wondering why it was acting
so #


& *


这篇关于定义我自己的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆