.NET和C# [英] .NET and C#

查看:56
本文介绍了.NET和C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

是否在.NET中有任何类,它将.NET数据类型转换为c#类型? (即获取一个.NET数据类型的
a变量并返回本机c#类型?)。

Rgds,

Komes

Hi everybody.
Is in .NET any class, which converts .NET data types to c# types? (i.e. gets
a variable of one of .NET data types and returns native c# type?).
Rgds,
Komes

推荐答案

komes写道:
komes wrote:

在.NET中任何转换的类。 NET数据

类型到c#类型? (即获取一个

.NET数据类型的变量并返回本机c#类型?)。
Is in .NET any class, which converts .NET data
types to c# types? (i.e. gets a variable of one of
.NET data types and returns native c# type?).



他们是一回事。将变量声明为int时或者

" float",它与写Int32相同。或者单一。


Eq。

They are the same thing. When you declare a variable as "int" or
"float", it''s the same as writing "Int32" or "Single".

Eq.


也许我正在拥有一个慢脑。那一天,但你能澄清一下你的意思吗?


C#并不真正拥有自己的任何数据类型(它只有编译时间

别名为CLR类型);类型是相同的 - 即typeof(int)==

typeof(Int32)。


你的意思是名字?即给它System.Int32。它返回int?在

这种情况​​下,我不知道任何内置的东西,但是别名列表并不是
长。你在谈论变量时有点让我失望 - 这是一个

代码生成器吗?


Marc
Maybe I''m having a "slow brain" day, but can you clarify what you mean?

C# doesn''t really have any data types of its own (it merely has compile-time
aliases to the CLR types); the types are the same - i.e. typeof(int) ==
typeof(Int32).

Do you mean the names? i.e. give it "System.Int32" and it returns "int"? in
which case I am not aware of anything inbuilt, but the list of aliases isn''t
long. You''re throwing me a bit by talking about variables - is this for a
code generator?

Marc


好的,这很清楚,但我在同一个代码中有另一个问题。我想

用system.io的二进制文件写一些数据。该方法有18个版本的b $ b版本,并采用不同数据类型的对象:bool,int等。我有一个常规对象,它有所有类型的数据 - 从数据库中读取。我想要做这样的事情:

对象o = ...

binarywriterobject.write(o as o.getType())

但当然这是不可能的,因为它就像转换为Type类型。

你知道如何解决这个问题吗?

Rgds,

Komes

OK, that''s clear, but I have another problem in the same code. I want to
write some data with binarywriter from system.io. That method has 18
versions and takes object of different data types: bool, int, and so on. I
have a regular object, which has data of all types - read from database. I
want to make something like this:
Object o =...
binarywriterobject.write(o as o.getType())
But of course it''s not possible, because it''s like convertion to Type type.
Have you any idea how to solve this?
Rgds,
Komes


这篇关于.NET和C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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