qq_37550403 2017-09-06 12:41 采纳率: 0%
浏览 2011

C# 关于typeof()运算符

以下是我看见的一个教程的示例,
前边写的是typeof(Int32),后边为何type.GetMethods()是获取的string类的方法,
typeof(Int32)返回的值是string类型的?本人是新手,求大神解答。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace TypeOf
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}

    private void btn_Get_Click(object sender, EventArgs e)
    {
        Type type = typeof(System.Int32);//获得int类型的Type对象
        foreach (MethodInfo method in type.GetMethods())//遍历string类中定义的所有公共方法
        {
            rtbox_text.AppendText(
                "方法名称:" + method.Name + Environment.NewLine);//输出方法名称
            foreach (ParameterInfo parameter in method.GetParameters())//遍历公共方法中所有参数
            {
                rtbox_text.AppendText(
                    "  参数:" + parameter.Name + Environment.NewLine);//输出参数名称
            }
        }
    }
}

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-07 01:40
    关注

    Type type = typeof(System.Int32)
    type.GetMethods()获取的是int32的方法
    你应该是看错了。比如说 ToString,Int32也有这个方法

    评论

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误