什么是typeof()函数? [英] What's the typeof() function for?

查看:387
本文介绍了什么是typeof()函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有人会给我一个typeof()函数的例子吗?什么是

for?

感谢您的帮助。


Jason

Hi,

Would someone give me an example for the typeof() function? What''s that
for?
Thanks for help.

Jason

推荐答案




Jason Huang写道:


"Jason Huang" wrote:


有人会给我一个typeof()函数的例子吗?那是什么?
感谢您的帮助。

Jason


您好


如果你需要使用serilize对象你必须指定我们需要使用的那种情况的类型

(typeof(Class Name) ),类对象)


问候

sambath R
Hi,

Would someone give me an example for the typeof() function? What''s that
for?
Thanks for help.

Jason

Hi

if u need to use serilize the object u have to specify the type of that
object
that situation we need to use (typeof("Class Name"), Class object)

Regards
sambath R



嗨Jason,

typeof返回一个Type实例,其中包含特定类型的所有类型信息

,这用于您想要查看的反射

在一个类型中查看它可能有多少方法,一个动态的返回类型

方法等。例如,您可以使用类型信息

来获取字符串类的所有静态方法,例如:

using System;

//使用System.Collections.Generic;

使用System.Text;

使用System.Reflection;


命名空间ConsoleApplication3

{

class program

{

static void Main(string [] args)

{

类型t = typeof(字符串);


MethodInfo [] methods = t.GetMethods();


foreach(方法中的MethodInfo方法)

{

if(method.IsStatic)

{

控制台.WriteLine(method.Name);

}

}


Console.ReadLine();

}

}

}

这是一个非常快速和简短的解释,开始研究更多内容

反思看看这些信息的力量。


希望有所帮助

Mark R Dawson
http://www.markdawson.org


" Jason Huang"写道:
Hi Jason,
typeof returns a Type instance that contains all of the type information
for a particular type, this is used for reflection where you want to look
inside a type to see maybe how many methods it has, the return type of a
method etc all dynamically. For example you could use the type information
to get all of the static methods of the string class like:
using System;
//using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Type t = typeof(string);

MethodInfo[] methods = t.GetMethods();

foreach (MethodInfo method in methods)
{
if(method.IsStatic)
{
Console.WriteLine(method.Name);
}
}

Console.ReadLine();
}
}
}
This is a really quick and brief explanation, start researching more into
reflection to see the power of this information.

Hope that helps
Mark R Dawson
http://www.markdawson.org

"Jason Huang" wrote:


有人会给我一个typeof()函数的例子吗?那是什么?
感谢您的帮助。

Jason
Hi,

Would someone give me an example for the typeof() function? What''s that
for?
Thanks for help.

Jason



Jason,


如果你经历了一个包含更多类型对象的集合,你想要处理这些对象,而不是它们都来自同一个父母和你

只需要派生的方法/属性,而不是你需要知道你正在处理的对象是什么类型的




我认为控件中控件的集合是最好的

样本,如果你想要更改所有复选框,你需要知道

类型控件是一个复选框。


我希望这有帮助,


Cor
Jason,

If you run through a collection with more types of objects and you want to
handle those than if they are not all derived from the same parent and you
only needs the derived methods/properties, than you need to know what type
of object you are handling.

Where in my opinion the collection of controls in a control is the nicest
sample, if you want to change all checkboxes than you need to know that the
type of the control is a checkbox.

I hope this helps,

Cor


这篇关于什么是typeof()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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