Tag: C#的

C#开启types

可能重复: C# – 有没有比这更好的替代“打开types”? C#不支持切换对象的types。 什么是模拟这个最好的模式: switch (typeof(MyObj)) case Type1: case Type2: case Type3: 谢谢!

dynamicreplaceC#方法的内容?

我想要做的是改变一个C#方法在被调用的时候的执行方式,这样我可以写下如下的东西: [Distributed] public DTask<bool> Solve(int n, DEvent<bool> callback) { for (int m = 2; m < n – 1; m += 1) if (m % n == 0) return false; return true; } 在运行时,我需要能够分析具有分布式属性(我已经可以做到)的方法,然后在函数正文执行之前和函数返回之前插入代码。 更重要的是,我需要能够在不调整Solve的地方修改代码,或者在函数启动的时候(编译时;在运行时这样做)。 目前我已经尝试了这一小段代码(假设t是Solve存储的types,m是Solve的MethodInfo) : private void WrapMethod(Type t, MethodInfo m) { // Generate ILasm for delegate. byte[] il = typeof(Dpm).GetMethod("ReplacedSolve").GetMethodBody().GetILAsByteArray(); // Pin […]

C#事件如何在幕后工作?

我正在使用C#,.NET 3.5。 我知道如何利用事件,如何在我的课堂上宣布他们,如何把他们从别的地方挂钩等。一个人为的例子: public class MyList { private List<string> m_Strings = new List<string>(); public EventHandler<EventArgs> ElementAddedEvent; public void Add(string value) { m_Strings.Add(value); if (ElementAddedEvent != null) ElementAddedEvent(value, EventArgs.Empty); } } [TestClass] public class TestMyList { private bool m_Fired = false; [TestMethod] public void TestEvents() { MyList tmp = new MyList(); tmp.ElementAddedEvent += new EventHandler<EventArgs>(Fired); tmp.Add("test"); […]

C ++中整数types存储的值的范围

在32位计算机上, unsigned long int保存十位数字(1,000,000,000 – 9,999,999,999)吗? 另外, unsigned long int , long int , unsigned int , short int , short unsigned int和int多less?

在OpenCV中增加摄像头捕捉分辨率

在我的C / C ++程序中,我使用OpenCV从我的摄像头捕捉图像。 相机( Logitech QuickCam IM )可以以320×240,640×480和1280×960的分辨率进行拍摄。 但是,由于一些奇怪的原因,OpenCV给我的分辨率只有320×240的图像。 调用使用cvSetCaptureProperty()与其他分辨率值更改分辨率不起作用。 如何使用networking摄像头捕捉其他分辨率的图像?

如何编译/连接升压与铿锵++ / libc ++?

这个问题的答案为什么不能在c ++ 0x模式下使用libc ++来链接这个boost :: program_options例子? 状态“你需要使用clang ++ -stdlib = libc ++来重buildboost。 我正在使用Mac OS Lion与叮当声V3.0。 如何使用clang构buildBoost v1.48.0并将其与libc ++链接? 更新:我创build了一个user-config.jam文件,内容如下: using clang-darwin …将用clang而不是gcc来构buildBoost。 如何链接libc ++而不是libstdc ++?

如何用Boostparsingini文件

我有一个ini文件,其中包含一些示例值,如: [Section1] Value1 = 10 Value2 = a_text_string 我试图加载这些值,并用Boost在我的应用程序中打印它们,但我不明白如何在C ++中执行此操作。 我在这个论坛search,以find一些例子(我总是使用C,所以我不是很好的C + +),但我只发现如何从文件一次读取值的例子。 我需要加载一个单一的值,如string = Section1.Value2因为我不需要读取所有的值,但只是less数。 我想加载单个值并将其存储在variables中,以便在我的应用程序中使用它们。 Boost可以做到这一点吗? 目前,我正在使用这个代码: #include <iostream> #include <string> #include <set> #include <sstream> #include <exception> #include <fstream> #include <boost/config.hpp> #include <boost/program_options/detail/config_file.hpp> #include <boost/program_options/parsers.hpp> namespace pod = boost::program_options::detail; int main() { std::ifstream s("file.ini"); if(!s) { std::cerr<<"error"<<std::endl; return 1; } std::set<std::string> options; options.insert("Test.a"); […]

使用C#上传文件到FTP

我尝试使用C#将file upload到FTP服务器。 该file upload,但零字节。 private void button2_Click(object sender, EventArgs e) { var dirPath = @"C:/Documents and Settings/sander.GD/Bureaublad/test/"; ftp ftpClient = new ftp("ftp://example.com/", "username", "password"); string[] files = Directory.GetFiles(dirPath,"*.*"); var uploadPath = "/httpdocs/album"; foreach (string file in files) { ftpClient.createDirectory("/test"); ftpClient.upload(uploadPath + "/" + Path.GetFileName(file), file); } if (string.IsNullOrEmpty(txtnaam.Text)) { MessageBox.Show("Gelieve uw naam in te geven […]

在C ++中将文件内容读入一个string

可能重复: 什么是最好的方法sl文件到一个std ::string在c + +? 在像Perl这样的脚本语言中,可以一次性将文件读入一个variables。 open(FILEHANDLE,$file); $content=<FILEHANDLE>; C ++中最有效的方法是什么?

Windows窗体:如何隐藏closures(x)button?

我有一个模式对话框,需要隐藏closures(X)button,但我不能使用ControlBox = false ,因为我需要保持最小化和最大化button。 我需要隐藏只是closuresbutton,有没有办法做到这一点? 非常感谢! 更新:我有权限禁用它,这是更简单:)谢谢大家!