电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

类型C# 大量函数

收藏

编号:338209658    类型:共享资源    大小:8.58MB    格式:PDF    上传时间:2022-10-12
  
15
金贝
分享到微信 分享到微博 分享到QQ空间
关 键 词:
C#大量函数
资源描述:
using System;using System.Collections.Generic;using System.Text;using Microsoft.Win32;对注册表操作using System.Collections;使用 Arraylistusing System.Security.Cryptography;力 口 密 解 密using System.IO;文件操作using System.Runtime.InteropServices;调用DLL Dlllmportusing System.Management;获取硬件信息using System.Net;获取IP地址是用到using System.Drawing;/imageusing System.Net.Networklnformation;/ping 用至Uusing System.Text.RegularExpressions;正则using System.Data;using System.Data.SqlClient;using Microsoft.VisualBasic;简体转繁体时用到using System.Web;/html UrlEncodeusing System.Net.Sockets;using System.Drawing.Drawing2D;图像操作using System.Drawing.Imaging;图像操作namespace函数库注册表操作public class GF_RegReadWrite(/读取路径为keypath,键名为keyname的注册表键值,缺省返回defIII/路径/键名/默认为nuH/static public bool GetRegVal(RegistryKey rootkey,string keypath,stringkeyname,out string rtn)(rtn=”;try(Registry Key key=rootkey.OpenSubKey(keypath);rtn=key.GetValue(keyname).ToString();key.Close();return true;)catch(return false;/设置路径为keypath,键名为keyname的注册表键值为keyval/static public bool SetRegVal(RegistryKey rootkey,string keypath,stringkeyname,string keyval)(try(RegistryKey key=rootkey.OpenSubKey(keypath,true);if(key=null)key=rootkey.CreateSubKey(keypath);key.SetValue(keyname,(object)keyval);key.Close();return true;)catch(return false;III创建路径为keypath的键private RegistryKey CreateRegKey(RegistryKey rootkey,string keypath)(try(return rootkey.CreateSubKey(keypath);catchreturn null;/删除路径为keypath的子项private bool DelRegSubKey(RegistryKey rootkey,string keypath)(try(rootkey.DeleteSubKey(keypath);return true;)catch(return false;)/删除路径为keypath的子项及其附属子项private bool DelRegSubKeyTree(RegistryKey rootkey,string keypath)(try(rootkey.DeleteSubKeyTree(keypath);return true;catch(return false;)/删除路径为keypath下键名为keyname的键值private bool DelRegKeyVal(RegistryKey rootkey,string keypath,stringkeyname)try(Registry Key key=rootkey.OpenSubKey(keypath,true);key.DeleteValue(keyname);return true;)catchreturn false;类型转换public class GF_Convert(/字符串转换char数组/summary/public static char string2chararray(string in_str,int in_len)(char ch=new charin_len;in_str.ToCharAn-ay().CopyTo(ch,0);return ch;)/char数组转换字符串/public static string chararray2string(char in_str)(string out_str;out_str=new string(in_str);int i=out_str.IndexOf(0;0);if(i=-l)i=16;return out_str.Substring(0,i);/byte数组转换字符串/public static string bytearray2string(byte in_str)(string out_str;out_str=System.Text.Encoding.Default.GetString(in_str);return out_str.Substring(0,out_str.IndexOf(0,0);)/字符串转换byte数组 注意转换出来会使原来的bytearray长度变短III/public static bytel string2bytearray(string in_str)(return System.Text.Encoding.Default.GetBytes(in_str);)/III字符串转换byte数组 长度为传如的长度III/传入字符串III 目标字节数组长度/public static byte string2bytearray(string in_str,int iLen)(byte bytes=new byteiLen;byte bsources=System.Text.Encoding.Default.GetBytes(in_str);Array.Copy(bsources,bytes,bsources.Length);return bytes;)/III将字符串编码为Base64字符串/III public static string Base64Encode(string str)(byte barray;barray=Encoding.Default.GetBytes(str);return Convert.ToBase64String(barray);/将Base64字符串解码为普通字符串/III public static string Base64Decode(string str)(byte barray;try(barray=Convert.FromBase64String(str);return Encoding.Default.GetString(barray);)catch(return str;)/图 片 转 换byte数组/public static bytef image_Image2Byte(Image pic,System.Drawing.Imaging.ImageFormat fmt)(Memory Stream mem=new MemoryStream();pic.Save(mem,fmt);mem.Flush();return mem.ToArrayO;/byte数组转换图片/III/public static Image image_Byte2Image(byte bytes)(Memory Stream mem=new MemoryStream(bytes,true);mem.Read(bytes,0,bytes.Length);mem.Flush();Image aa=Image.FromStream(mem);return aa;Ill/i p转换长整形/public static long IP2Long(string strIP)(long ip=new long4;string s=strlP.Split(V);ip0=long.Parse(s0);ipfl=long.Parse(sl);ip2=long.Parse(s2);ip3=long.Parse(s3);return(ip0 24)+(ipl 16)+(ip2 8)+ip3;)/长整 形转换IP/public static string Long2IP(long longlP)StringBuilder sb=new StringBuilder(,H,);sb.Append(longIP 24);sb.Append(n.n);将高8位置0,然后右移16为sb.Append(longIP&OxOOFFFFFF)16);sb.Append(n.H);sb.Append(longIP&OxOOOOFFFF)8);sb.Append(.H);sb.Append(longIP&OxOOOOOOFF);return sb.ToStringO;/将8位日期型整型数据转换为日期字符串数据III/整型日期/是否以中文年月日输出v/param/public static string FormatDate(int date,bool chnType)(string dateStr=date.ToString();if(date=0 II dateStr.Length!=8)return dateStr;if(chnType)return dateStr.Substring(O,4)+“年+dateStr.Substring(4,2)+月 +dateStr.Substring(6)+B;return dateStr.Substring(O,4)+dateStr.Substring(4,2)+dateStr.Substring(6);/string型底换为bool型/III 要转换的字符串III 缺省值/vretums转换后的bool类型结果public static bool StrToBool(object expression,bool defValue)(if(expression!=null)return StrToBool(expression,defValue);return defValue;)/string型需换为bool型/要转换的字符串/缺省值III$换后的bool类型结果/returnspublic static bool StrToBool(string expression,bool defValue)(if(expression!=null)(if(string.Compare(expression,ntruen,true)=0)return true;else if(string.Compare(expression,false,true)=0)return false;)return defValue;)/将对象转换为Int32类型/要转换的字符串/缺省fi/returns 转换后的 int 类型结果 public static int ObjectToInt(object expression)(return ObjectToInt(ex
展开阅读全文
提示  金锄头文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:C# 大量函数
链接地址:https://www.jinchutou.com/shtml/view-338209658.html
关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.