//定义类
public class MyClass
{
public int Property1 { get; set; }
}
static void Main()
{
MyClass tmp_Class = new MyClass();
tmp_Class.Property1 = 2;
Type type = tmp_Class.GetType(); //获取类型
System.Reflection.PropertyInfo propertyInfo = type.GetProperty("Property1"); //获取指定名称的属性
int value_Old = (int)propertyInfo.GetValue(tmp_Class, null); //获取属性值
Console.WriteLine(value_Old);
propertyInfo.SetValue(tmp_Class, 5, null); //给对应属性赋值
int value_New = (int)propertyInfo.GetValue(tmp_Class, null);
Console.WriteLine(value_New);

}

其它应用请参考:http://www.bitscn.com/pdb/dotnet/200804/138760.html

c# 如何通过反射 获取\设置属性值、的更多相关文章

  1. c# 如何通过反射 获取\设置属性值

    c# 如何通过反射 获取\设置属性值 //定义类public class MyClass{public int Property1 { get; set; }}static void Main(){M ...

  2. c#利用反射获取对象属性值

    public static string GetObjectPropertyValue<T>(T t, string propertyname){     Type type = type ...

  3. 【java】之Method和Field反射获取和设置属性值

    package com.javaluna.reflect; import java.lang.reflect.Field; import java.lang.reflect.Method; impor ...

  4. 如何获取value值,获取属性值,设置属性值,

    1.获取select下拉框的value值,   2.获取select  的tid值 3.设置属性值  4.判断哪个单选框选中了 prop好像是判断的意思吧,个人理解勿喷谢谢!!!!!!

  5. JS中使用document.defaultView.getComputedStyle()、currentStyle()方法获取CSS属性值

    在对网页进行调试的过程中,经常会用到js来获取元素的CSS样式,方法有很多很多,现在仅把我经常用的方法总结如: 1. obj.style:这个方法只能JS只能获取写在html标签中的写在style属性 ...

  6. java 通过反射获取类属性结构,类方法,类父类及其泛型,类,接口和包

    首先自定义三个类 package reflection1; public interface MtInterface { void info(); } package reflection1; imp ...

  7. 2019-4-16-C#-使用反射获取私有属性的方法

    title author date CreateTime categories C# 使用反射获取私有属性的方法 lindexi 2019-4-16 10:13:3 +0800 2018-09-26 ...

  8. ASP.NET Core EF 查询获取导航属性值,使用Include封装

    // 引用 using Microsoft.EntityFrameworkCore; // 摘要: // Specifies related entities to include in the qu ...

  9. JQ获取元素属性值

    最近在学习JAVA Web,自己也是做个下列表左右选择的小案例. 获取某个元素的属性值一直以为是要调用atrr方法,不过好像获取元素的数组形式再遍历每个元素的时候想获取到它的属性值用attr方法有问题 ...

随机推荐

  1. SpringMVC经典系列-13使用SpringMVC处理Ajax请求---【LinusZhu】

    注意:此文章是个人原创,希望有转载须要的朋友们标明文章出处,假设各位朋友们认为写的还好,就给个赞哈,你的鼓舞是我创作的最大动力,LinusZhu在此表示十分感谢,当然文章中如有纰漏,请联系linusz ...

  2. Delphi 调用批处理

    uses ShellApi; procedure TForm1.Button1Click(Sender: TObject); var filename, Path: string; begin fil ...

  3. Nginx重要结构request_t解析之http请求的获取

    请在文章页面明显位置给出原文连接,否则保留追究法律责任的权利. 本文主要参考为<深入理解nginx模块开发与架构解析>一书,处理用户请求部分,是一篇包含作者理解的读书笔记.欢迎指正,讨论. ...

  4. matlab2013a for linux/Ubuntu 安装步骤及创建快捷方式(ubuntu14.04下安装)

    1.挂载安装镜像:sudo mount -o loop myfile.iso /media/mnt   #挂载ISO文件,使用參数 -o loop      mnt为已经建立好的文件夹. 2.运行安装 ...

  5. C#泛型比较大小

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. IPv6 neighbor discovery

    IPv6 neighbor discovery By stretch | Thursday, August 28, 2008 at 5:03 a.m. UTC Neighbor Discovery P ...

  7. kali2.0如何安装中文输入法

    由于kali的更新源是国外网站,替换成国内的镜像站,具体操作如下: 打开终端输入 leafpad /etc/apt/sources.list   把下面的源粘贴进去,原有内容注释掉 #中科大源deb  ...

  8. PostgreSQL 修改列报错:cannot be cast automatically to type integer

    如果你直接使用可视化工具修改一个varchar字段为int类型的时候,可能会报错, 这里就需要自己去写一个语句去修改了 调整执行语句:ALTER TABLE table_name ALTER COLU ...

  9. Unity3D 3D坦克大战

    视频学习来源 移动和旋转 using UnityEngine; using System.Collections; /* * Adminer:sun2955 * http:www.yinghy.com ...

  10. CSS的!important修改权重

    !important语法和描述 !important为开发者提供了一个增加样式权重的方法.应当注意的是!important是对整条样式的声明,包括这个样式的属性和属性值. #example { fon ...