惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
IT之家
IT之家
J
Java Code Geeks
博客园_首页
Stack Overflow Blog
Stack Overflow Blog
量子位
I
InfoQ
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
V
V2EX
博客园 - Franky
U
Unit 42
S
SegmentFault 最新的问题
美团技术团队
The Register - Security
The Register - Security
Last Week in AI
Last Week in AI
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
博客园 - 叶小钗
M
MIT News - Artificial intelligence
博客园 - 聂微东
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Troy Hunt's Blog
B
Blog
P
Palo Alto Networks Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
K
Kaspersky official blog
The GitHub Blog
The GitHub Blog
C
Cisco Blogs
Microsoft Azure Blog
Microsoft Azure Blog
F
Fortinet All Blogs
S
Schneier on Security
C
CERT Recently Published Vulnerability Notes
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
小众软件
小众软件
T
Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Martin Fowler
Martin Fowler
AWS News Blog
AWS News Blog
V
Visual Studio Blog
Simon Willison's Weblog
Simon Willison's Weblog
H
Heimdal Security Blog

博客园 - angushine

获得本机IP地址 设置eclipse文件默认的编码方式 Eclipse Helios的PermGen space错误的解决办法 取指定长度的字符串(双字节算2) - angushine - 博客园 截取指定长度字符串 Silverlight项目无法启动调试 增强 VSS 的文件共享安全性 兼容各个版本浏览器的设置最小宽度 动态分配一维数组 浏览器区别 封装log4net C#获得调用方法的名称和类名 jQuery全选/全消CheckBox以及JS回调一例 MySQL绿色安装方法1 WebBrowser中调用加载页面的Javascript方法 定时更新内存和虚拟内存 多线程中更新组件 Request、Request.QueryString、Request.Form与Request.Params 开始→运行→输入的命令集锦(转载)
反射调用静态方法
angushine · 2009-10-12 · via 博客园 - angushine

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;namespace ConApp
{
    
class Program
    {
        
static void Main(string[] args)
        {
            
// 使用TryParse,出现异常时,赋值为最小值
            string str = "4x";
            DateTime dt 
= DateTime.MaxValue;
            DateTime.TryParse(str, 
out dt);// 使用TryParse,出现异常时,赋值为最小值
            int i = 2;
            
int.TryParse(str, out i);// 调用静态方法
            Type t = typeof(Sys);
            
object obj = t.InvokeMember("GetName",
                    BindingFlags.InvokeMethod 
| BindingFlags.Static | BindingFlags.Public, nullnullnew object[] { 2 });// 调用一般方法
            Type type = typeof(Sys);
            Object objT 
= type.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, nullnull, args); 
            
int ii = (int)type.InvokeMember("GetInt", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, objT, new object[] { 1 }); 

            Console.ReadKey();
        }
    }

public class Sys
    {
        
public static string GetName(int id)
        {
            
return string.Format("Your name is : test_{0}", id + 1);
        }
public int GetInt(int value)
        {
            
return value + 100;
        }
    }
}