随笔分类 -  C#

摘要:1 #ifndef _ZTC_DELEGATE_H_ 2 #define _ZTC_DELEGATE_H_ 3 4 #include 5 #include 6 7 /////////////////////////////////////////////// 8 // C++ 使用 可变参数模板类, 来实现 9 // C#中的 委托10 // Anchor: ztc11 // Date : 2014-01-1012 ///////////////////////////////////////////////13 14 template15 class Delegate {16 p... 阅读全文
posted @ 2014-01-10 12:11 easyfrog 阅读(886) 评论(0) 推荐(0)
摘要:Unity C# 调用 C++ DLL 并在 DLL 中调用 C# 的回调函数~~~ 呵呵... 看着有点晕..再解释一下就是 在Unity中 使用 C# 调用 C++ 写的 DLL, 但是在这个 C++ 的 DLL 的某一个方法中,用到的 回调函数. 也就是需要 在 C# 中传入一个与 C++中签名相同的 方法的问题.一般在 C++ 中 使用 这种文件 创建一个函数的指针 : // 开辟内存空间的函数指针 (float *& 为float型指针的引用) typedef void (*AllocSpace)(int,int,int,float*&,float*&,int 阅读全文
posted @ 2013-11-23 00:53 easyfrog 阅读(2347) 评论(0) 推荐(0)
摘要:1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace CompilerTest 7 { 8 // Compiler 9 class MyCompilter 10 { 11 // Provider 12 private Microsoft.CSharp.CSharpCodeProvider Provider; 13 // CompilerPar... 阅读全文
posted @ 2013-07-03 20:21 easyfrog 阅读(514) 评论(0) 推荐(0)
摘要:1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.IO; 6 using System.Runtime.Serialization.Formatters.Binary; 7 8 namespace SerializeTest 9 {10 class Program11 {12 static void Main(string[] args) {13 // Create a... 阅读全文
posted @ 2013-06-23 17:31 easyfrog 阅读(1100) 评论(0) 推荐(0)
摘要:1 // 模拟一个处理消息队列的类 2 class MessageHandler 3 { 4 // 消息队列 5 private Queue<string> messageQue = new Queue<string>(); 6 private Thread th = null; 7 private bool can = true; 8 9 // 处理消息队列的方法10 void HandlerMessage() {11 while (can) {12 ... 阅读全文
posted @ 2013-06-17 21:55 easyfrog 阅读(1289) 评论(0) 推荐(0)
摘要:1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.Threading;10 11 namespace InvokeTest12 {13 public partial class Form1 : Form14 ... 阅读全文
posted @ 2013-06-17 21:53 easyfrog 阅读(3312) 评论(3) 推荐(1)
摘要:1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading; 6 7 namespace ThreadTest 8 { 9 class Program10 {11 // 信号 12 static AutoResetEvent ar = new AutoResetEvent(false);13 14 // 一个公用的变量15 static... 阅读全文
posted @ 2013-06-17 21:49 easyfrog 阅读(402) 评论(0) 推荐(0)
摘要:在写程序时, 可以把用到的 图标,图片,声音等外部资源,放在一个 .resx (资源文件)中. 这样的好处是不用考虑什么路径的问题.而且还对资源有保护的做用.1.创建一个 ResourceFile.resx 文件. (ResourceFile 可以为自定义的任意名称)2.向ResourceFile.resx 里添加资源文件 .3.可以直接在C# 文件中这样使用: 比如:主窗体的图标: this.Icon = (Icon)(ResouceFile.ResourceManager.GetObject("资料的名称无后缀")); 阅读全文
posted @ 2012-11-18 14:23 easyfrog 阅读(10214) 评论(0) 推荐(0)
摘要:DES 加密的一些名词 : 原字符串 加密后字符串 密钥 与 向量1。将原字符串转为 字节数组.使用 UTF8解码。byte[] InputStrArr = System.Text.Encoding.UTF8.GetBytes(InputStr);2.得到密钥与向量的字节数组 都为8位。byte[] key ;byte[] iv;// 创建一个DESDESCryptoServiceProvider des = new DESCryptoServiceProvider();// 创建一个内存流,用来将加密后的字节写入。 MemoryStream ms = new Memor... 阅读全文
posted @ 2012-11-16 17:07 easyfrog 阅读(488) 评论(0) 推荐(0)
摘要:连接字条串: "server = xxx.gotoip.net,1435;database = theTable;uid = xxxxx;pwd = xxxxx"选择 : select * from theTable select xxx,xxx,xxx, from theTable where xx = 'xxxx' or xx like '%xx%'增加 : Insert into theTable (xxx,xxx,xxx) values (xxx,xxx,xxx)修改 : update theTabel set xxx = ' 阅读全文
posted @ 2012-11-16 13:51 easyfrog 阅读(398) 评论(0) 推荐(0)
摘要:现在非常的流行使用C++来完成底层的算法或是需要高运行速度的程序快。然后使用 C# 来调用。用C#来写界面和逻辑层。 这样即用到了 C++ 的运行速度又用到了C# 快速的开发优势。下面讲一下如何在C#中调用 C++生成的dll :// cppdll.cpp 因为这个DLL的目的就是为了让 C#去调用。所以这里不用// 再去写个头文件了,写头文件主要是为了让 C++的程序去调。我们这里// 是把函数的声明与定义都写在一起。#include using namespace std;// 把固定要使用的 “extern "C" __declspec(dllexport)”,放在函 阅读全文
posted @ 2012-11-13 10:08 easyfrog 阅读(959) 评论(0) 推荐(0)
摘要:C# 中的线程 Thread的定义与使用:1.默认是需要传一个无返回值无参数的方法:void Func();Thread th = new Thread(Func);th.Start();2.默认的向线程中传值,使用的是ParameterizedThreadStart(Object obj).,无返回值 。它传入的是一个 Object类型的参数。 void Func(Object obj);Thread th = new Thread(new ParameterizedThreadStart(Func)); th.Start(something);3.我们可以使用一个类把... 阅读全文
posted @ 2012-11-09 16:34 easyfrog 阅读(736) 评论(0) 推荐(0)
摘要:Array中的Linq 方法 :Where Count Select 示例数组:int[] intArray = {12,3,24,56,8,65,23}; 1. where --> 是筛选方式. 将一个序列中按条件筛选,放到返回的新序列中 如: 将示例数组中 大于30的数提取出来放到新的序列中. IEnumerable<int> result = intArray.where<int>(x => x > 30); 2.count --> 是计数方式. 得到一个序列中满足条件的元素的个数 如: 得到示例数组中有几个元素大于 20. int cnt 阅读全文
posted @ 2012-10-13 22:07 easyfrog 阅读(4773) 评论(0) 推荐(1)
摘要:View Code 1 using System; 2 3 // 声名一个代理,与类同级(其本质就是类) 4 delegate void theHandler(int i); 5 6 class TestClass 7 { 8 public void plus(int i) { 9 Console.WriteLine( " i + i = " + (i + i).ToString());10 }11 // 这个方法中的第一个参数 是一个代理.12 // 我们可以直接传入一个与其签名相同的 方法名.13 public void del... 阅读全文
posted @ 2012-05-05 18:10 easyfrog 阅读(384) 评论(0) 推荐(0)
摘要:C# 异步调用的学习 BeginInvoke ManualRestEventView Code 1 using System; 2 using System.Threading; 3 4 class AsyncTest 5 { 6 // 声明一个委托,与你要异步的方法有同样的签名 7 // 其实就是用委托把一个方法包裹了一下.这样就可以 8 // 使用 委托的 IAsyncResult BegionInvoke(AsyncCallback callback,Object object) 9 // 方法实现异步操作10 public delegate void AsyncEv... 阅读全文
posted @ 2012-03-13 16:06 easyfrog 阅读(788) 评论(0) 推荐(0)
摘要:优雅的解决 多线程中访问 UI 的问题1.在WinForm 程序中可以在Form的构造函数中. 将 "是否检察跨线程的控件访问" 设为 False. 就解决了. 就可以正常的使用控件了. Control.CheckForIllegalCrossThreadCalls = false;2.就是使用控件的Invoke 方法比如: label1.Invoke(new MethodInvoker(delegate () {this.label1.text = "靠...!";}));使用Lambda 表达示会更优雅一点: label1.Inovke(new Me 阅读全文
posted @ 2012-02-08 18:46 easyfrog 阅读(4726) 评论(0) 推荐(0)
摘要:用C# GDI+ 来模拟 WIN7 的水泡屏保.需要解决以下三个问题: 1.水泡与边缘碰撞的模拟 2.水泡之间的碰撞模拟.3.创建水泡(Ball)的类 1.水泡与边缘碰撞的模拟其实很简单. 一开始.我还觉得还需要用反弹公式去计算. 后来才发现. 只在X,Y(水泡的位置),在到边缘时取下负值即可模拟. View Code 1 public void Move(int gameWidth,int gameHeight) 2 { 3 if (X < 0 || X > gameWidth - Radius * 2) { // 在X的值小于0 或... 阅读全文
posted @ 2012-02-06 22:56 easyfrog 阅读(3257) 评论(4) 推荐(2)
摘要:为控制增加双缓冲 的目 的为了在重绘时避免闪烁.Panel类的setStyle 方法不是Public的. 所以我们需要自定义一个Panel类,在其构造函数中定义setStyle.this.SetStyle(ControlStyles.AllPaintingInWmPaint|//不擦除背景 ,减少闪烁 ControlStyles.OptimizedDoubleBuffer|//双缓冲 ControlStyles.UserPaint,//使用自定义的重绘事件,减少闪烁 true);代码实例: 阅读全文
posted @ 2012-02-04 23:10 easyfrog 阅读(4174) 评论(1) 推荐(0)
摘要:在使用SharpDevelop编写C#程序时,经常要用到 外部的资源文件,比如:图片,声音等. 我们需要将这些谁的嵌入我们的程序.dll or .exe中. 方法如下:在工程树中点 右键->添加项->其它->空资源文件.需要引入Resources 命名空间:using System.Resources;创建一个ResourceManager (资源管理类的实例):ResourceManager rm = new ResourceManager("nameSpace.Properties.MyRes",this.GetType().Assembly); &q 阅读全文
posted @ 2012-02-04 09:08 easyfrog 阅读(1794) 评论(1) 推荐(3)
摘要:SharpDevelop4.1 功能强大.跟VS 相差无几了 ,但体积只有16.7M(安装文件). 一直在用它写C#程序.前段时间看了VIM等编辑器的深色配色很酷. 所以为SharpDevelop也弄了一个..效果如下:下载地址:http://www.cglobal.0fees.net/tmp/SharpDevelopProperties.xml(放入位置:C:\Users\你的机器名\AppData\Roaming\ICSharpCode\SharpDevelop4)*此配色只适用于sharpdevelop4.1* 阅读全文
posted @ 2012-01-15 20:53 easyfrog 阅读(2401) 评论(11) 推荐(2)