Tag: C#的

EntityFramework – 包含组合键的查询

给出一个ID列表,我可以查询所有相关的行: context.Table.Where(q => listOfIds.Contains(q.Id)); 但是当表有复合键时,你如何实现相同的function呢?

如何在iOS中处理不同的方向

补充 :你可以在github ios6rotations上访问这个项目 对不起,在iOS 6中提问有关屏幕旋转的问题,但这真的是一个痛苦的屁股..我仍然无法完全理解 – 由于某种原因,它在某些情况下行为不同。 我在testing应用程序中有以下简单的视图层次结构: 我试图达到的目的是 – 只将蓝色控制器保持在风景中,而红色控制器只能用于风景 。 我有这样的代码里面的UINavigationController的子类: @implementation CustomNavController – (BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; } – (NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; } – (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; } @end 在我的蓝色控制器中我实现了这个: – (BOOL)shouldAutorotate { return YES; } – (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } 而在红色的控制器中: – […]

字节数组到图像转换

我想将字节数组转换为图像。 这是我从哪里得到字节数组的数据库代码: public void Get_Finger_print() { try { using (SqlConnection thisConnection = new SqlConnection(@"Data Source=" + System.Environment.MachineName + "\\SQLEXPRESS;Initial Catalog=Image_Scanning;Integrated Security=SSPI ")) { thisConnection.Open(); string query = "select pic from Image_tbl";// where Name='" + name + "'"; SqlCommand cmd = new SqlCommand(query, thisConnection); byte[] image =(byte[]) cmd.ExecuteScalar(); Image newImage = byteArrayToImage(image); Picture.Image = newImage; //return […]

是否有可能从一个控件“偷”一个事件处理程序,并将其交给另一个?

我想要做这样的事情: Button btn1 = new Button(); btn1.Click += new EventHandler(btn1_Click); Button btn2 = new Button(); // Take whatever event got assigned to btn1 and assign it to btn2. btn2.Click += btn1.Click; // The compiler says no… 在类中已经定义了btn1_Click: void btn1_Click(object sender, EventArgs e) { // } 这当然不会编译(“事件”System.Windows.Forms.Control.Click“只能出现在+ =或 – =”的左侧)。 有没有办法从一个控件采取事件处理程序,并将其分配给另一个在运行时? 如果这是不可能的,重复的事件处理程序,并分配给另一个控制在运行时可以吗? 有几点:我已经search了一段时间,发现没有办法。 大多数尝试的方法都涉及到reflection,所以如果您阅读我的问题,并认为答案是非常明显的,请尝试先在Visual Studio中编译代码。 或者,如果答案真的非常明显,请随时给我打电话。 […]

我可以假设(布尔)真的==(INT)1为任何C + +编译器?

我可以假设(bool)true == (int)1为任何C + +编译器?

App.Config更改值

这是我的App.Config <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="lang" value="English"/> </appSettings> </configuration> 有了这个代码我做了改变 lang = "Russian"; private void Main_FormClosing(object sender, FormClosingEventArgs e) { System.Configuration.ConfigurationManager.AppSettings.Set("lang", lang); } 但它不会改变。 我做错了什么?

内置types是否有默认的构造函数?

在读完这篇文章之后,我提出了一个观点: int ()产生0,因为临时int是初始化的值,而不是因为int()调用int()的默认构造函数。 (根据我的理解,这篇文章有缺陷。) 我也说过,原始(内置)types没有构造函数。 原作者要求我检查部分$ 10.4.2(TC ++ PL)的内容 内置types也有默认的构造函数($ 6.2.8) 但我仍然认为“C ++”语句甚至允许内置types(原始types)具有默认的构造函数。 是有缺陷的(按照C ++ 03)。 我认为TC ++ PL中的Bjarne混合了“构造函数如符号ie () ”与实际的构造函数调用。 Bjarne写这本书的时候并没有引入价值初始化,对吧? 那么TC ++ PL中的文本是不正确的,按照C ++ 98和C ++ 03? 你们有什么感想? 编辑 我亲自(通过邮件)向Bjarne询问了TC ++ PL中有缺陷的文本,这是他的回答 我想你混淆了“实际构造函数调用”与概念上有一个构造函数。 内置types被认为是有构造函数 (无论标准用来描述它们的行为的话)。

C中的双指针const正确性警告

指向非const数据的指针可以隐式转换为指向相同types的const数据的指针: int *x = NULL; int const *y = x; 添加额外的const限定符以匹配额外的间接参数应该在逻辑上以相同的方式工作: int * *x = NULL; int *const *y = x; /* okay */ int const *const *z = y; /* warning */ 然而,用GCC或Clang编译这个与-Wall标志,会导致以下警告: test.c:4:23: warning: initializing 'int const *const *' with an expression of type 'int *const *' discards qualifiers in nested pointer types […]

为什么unsigned int不符合CLS?

为什么无符号整数不符合CLS? 我开始认为型号规格只是为了性能,而不是正确性。

如何检查结构消耗的字节数?

如果我正在创build一个相对较大的结构,我如何计算它在内存中占用的字节呢? 我们可以手动做,但如果结构足够大,那么我们该怎么做呢? 有一些代码块或应用程序?