c#-3.0

How does generic type inference work in C#?

↘锁芯ラ 提交于 2019-12-20 01:43:57
问题 If I have the following code private BaseMessage getMessage() { return new OtherMessage(); } private void CheckType<T>(T type) { Console.WriteLine(type.GetType().ToString()); Console.WriteLine(typeof(T).ToString()); } private void DoChecks() { BaseMessage mess = getMessage(); CheckType(mess); } why do I get different types outputted? Is there anyway of getting the type inference to use the actual type of the object being passed? 回答1: Generic type inference means that the compiler

About PropertyStore and MDI child form

霸气de小男生 提交于 2019-12-20 01:43:15
问题 This is .net WinForm question about MDI setting. When the main form creates an MDI child form, the main form's PropertyStore holds a reference to the MDI child form. I wonder whether this will cause the child form to be alive even if it is closed. If so, what shall I do when disposing the child form in order to remove this reference? The child form is called by sample code: //The code is in the main form. var f = new FormMDIChild(); f.MdiParent = this; f.Show(); 回答1: For the record, the

Conditional Reference

a 夏天 提交于 2019-12-20 01:37:45
问题 I have an application that I was writing that communicates with a third-party application via a Component Object Model library. I must reference this COM library within the Visual Studio project itself in order for the application I am writing to work. There is also a .NET wrapper library that I must reference in the Visual Studio project in order to communicate with the COM library. Is there a way to to create a conditional initialization of a class, in order to use a method within a .NET

Sliding window algorithm in C#

随声附和 提交于 2019-12-19 11:28:07
问题 I'm trying to implement simple sliding window alogirithm on two-dimensional array in C# 3.0, I found this as very useful but it involves only single-dimensioal array. The post also includes the code for the algo, I'm totaly failed to use it for my senario... can any one suggest me how do I proceed? Scenario: (source: googlepages.com) The above image is 10X10 matrix and need get 3X3 matrix out it, using any algorithm (Sliding window would be greate). Red rectangle is a first set and green one

Java: Does String.Format exist in Java like in C#?

ⅰ亾dé卋堺 提交于 2019-12-19 08:07:53
问题 Something I discovered I like about C# are properties & String.Format. Does something like String.Format from C# exist in Java? C# ex: int myNum = 2; int myNumSq = myNum * myNum; String MyString = String.Format("Your lucky numbers are: {0}, & {1}", myNum, myNumSq); 回答1: It' even called String.format(): String myString = String.format("Your lucky numbers are: %d, & %d", myNum, myNumSq); This method is available since Java 1.5. 回答2: Yes, the class in question is "MessageFormat": http://download

LinQ distinct with custom comparer leaves duplicates

泄露秘密 提交于 2019-12-18 21:26:12
问题 I've got the following classes: public class SupplierCategory : IEquatable<SupplierCategory> { public string Name { get; set; } public string Parent { get; set; } #region IEquatable<SupplierCategory> Members public bool Equals(SupplierCategory other) { return this.Name == other.Name && this.Parent == other.Parent; } #endregion } public class CategoryPathComparer : IEqualityComparer<List<SupplierCategory>> { #region IEqualityComparer<List<SupplierCategory>> Members public bool Equals(List

evaluating cost/benefits of using extension methods in C# => 3.0 [closed]

橙三吉。 提交于 2019-12-18 16:46:50
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . In what circumstances (usage scenarios) would you choose to write an extension rather than sub-classing an object ? < full disclosure : I am not an MS employee; I do not know Mitsu Furota personally; I do know the author of the open-source Componax library mentioned here, but

Executing a certain action for all elements in an Enumerable<T>

僤鯓⒐⒋嵵緔 提交于 2019-12-18 13:51:11
问题 I have an Enumerable<T> and am looking for a method that allows me to execute an action for each element, kind of like Select but then for side-effects. Something like: string[] Names = ...; Names.each(s => Console.Writeline(s)); or Names.each(s => GenHTMLOutput(s)); // (where GenHTMLOutput cannot for some reason receive the enumerable itself as a parameter) I did try Select(s=> { Console.WriteLine(s); return s; }) , but it wasn't printing anything. 回答1: A quick-and-easy way to get this is:

Loading DataTable Slow When Bound to DataGridView.Datasource

心不动则不痛 提交于 2019-12-18 12:47:24
问题 I've searched all over and I can't figure this one out. I am working on a Winforms UI that is pulling large volumes of rows that I need to display in a DataGridView. I have already read all about limiting row counts and paging and there is absolutely no good way for me to do this. Basically I am working on the TargetDataViewer control of the Extended Events Manager for SQL Server 2008 that I wrote on Codeplex. http://extendedeventmanager.codeplex.com/ I am limited to what I can do based on

Simple Examples of joining 2 and 3 table using lambda expression

痴心易碎 提交于 2019-12-18 11:09:13
问题 Can anyone show me two simple examples of joining 2 and 3 tables using LAMBDA EXPRESSION( for example using Northwind tables (Orders,CustomerID,EmployeeID)? 回答1: Code for joining 3 tables is: var list = dc.Orders. Join(dc.Order_Details, o => o.OrderID, od => od.OrderID, (o, od) => new { OrderID = o.OrderID, OrderDate = o.OrderDate, ShipName = o.ShipName, Quantity = od.Quantity, UnitPrice = od.UnitPrice, ProductID = od.ProductID }).Join(dc.Products, a => a.ProductID, p => p.ProductID, (a, p) =