C#反射(System.Reflection )
[@more@]C# System.Reflection 反射 反射的概述 反射appDomain 的程序集 反射单个程序集 利用反射获取类型信息 设置反射类型的成员 通过反射创建类型的实例 反射类型的接口 反射的性能 反射的概述 反射的定义:审查元数据并收集关于它的类型信息的能力。元数据(编译以后的最基本数据单元)就是一大堆的表,当编译程序集或者模块时,编译器会创建一个类定义表,一个字段定义表,和一个方法定义表等,。System.reflection命名空间包含的几个类,允许你反射(解析)这些元数据表的代码
C#将自己的程序添加到右键菜单
[@more@]命名空间:using Microsoft.Win32;右键菜单的注册表项在HKEY_CLASSES_ROOT*shell下关键代码:RegistryKey reg;reg = Registry.ClassesRoot;reg=reg.CreateSubKey(@"*shellmyApp");//创建新项myAppreg.SetValue("","程序名称");//设置项值reg = Registry.ClassesRoot;reg.CreateSubKey(@"*shellmyAppcommand");//创建新项commandreg.SetValue("",Application.ExecutablePath+" %1");//设置command的值reg.Close();
Visual C# 快捷键
[@more@]F1“帮助”菜单 ->“F1 帮助”F3“编辑”菜单 ->“查找下一个”F4“视图”菜单 ->“属性窗口”F5“调试”菜单 ->“开始”F6“窗口”菜单 ->“下一个拆分窗格”F7“视图”菜单 ->“查看代码”F8“编辑”菜单 ->“转到下一位置”F9“调试”菜单 ->“切换断点”F10“调试”菜单 ->“逐过程”F11“调试”菜单 ->“逐语句”F12“编辑”菜单 ->“转到定义”Insert“编辑”菜单 ->“改写模式”Backspace“编辑”菜单 ->“向后删除”Enter“编辑”菜单 ->“分行”Esc“窗口”菜单 ->“激活文
C#控制只能程序运行一个
[@more@]以下代码是使用C#控制只能程序运行一个,不能同时运行两个:static void Main() { bool flag=false; System.Threading.Mutex mutex=new System.Threading.Mutex(true,"YourMutexName",out flag); if ( !flag ) { Application.Exit(); MessageBox.Show("Runing"); return; } Application.Run(new frmMain()); }
C#网络编程经典代码
[@more@]using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Net;using System.Net.Sockets;using System.IO;using System.Threading;namespace connect{/// <summary>/// Summary description for Form1./// </summary>public class Form1 : System.Windows.Forms.Form{ private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private TcpClient client;//新加的 private
C#函数实现的小功能集合
[@more@]子窗体返回主窗体 /**////<summary> ///名称:redirect ///功能:子窗体返回主窗体 ///参数:url ///返回值:空 ///</summary> public void redirect(string url,Page page) { if ( Session["IfDefault"]!=(object)"Default") { page.RegisterStartupScript("","<script>window.top.document.location.href='"+url+"';</script>"); } } 判断是否为数字 /**//// <summary> /// 名称:IsNumberic /// 功能:判断输入的
用C#將字符串用MD5加密
[@more@]/// /// 將字符串用MD5加密/// /// 要加密的字符串/// 加密後的字符串public static string EncryptPassword(string strPwd){byte [ ] hashedBytes;string temp;String strMD5;MD5 md5Hasher = new MD5CryptoServiceProvider();UTF8Encoding encoder = new UTF8Encoding();hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(strPwd));strMD5 = string.Empty;for (int i = 0; i <= hashedBytes.Length - 1; i++){temp = hashedBytes [i].ToString("X");if (temp.Length == 1){temp = "0" + temp;strMD
用C#檢查字符串中是否有Unicode字符
[@more@] /// <summary> /// 檢查strInput中是否有Unicode字符 /// </summary> /// <param name="strInput">要檢查的字符串</param> /// <returns>true:有Unicode字符; false:沒有Unicode字符</returns> public static bool CheckExistUnicode(string strInput) { int i = strInput.Length; if (i == 0) return false; int j = System.Text.Encoding.Default.GetBytes(strInput).Lengt