.net-4.0

Adding Description to each Tuple object?

随声附和 提交于 2019-12-12 16:09:01
问题 I have a tuple of : var a = new Tuple<int, int, int>(1,2,3); My question : is there any way (by /// remark or something else ), to add a short description to the object types ? the first 3 int's can be confusing.... How can I know that item1 is refering to "age" and not to "Number of fingers" ? 回答1: No. The Tuple class is only intended to be used internally within a method; if you intend to make the data available publicly, you should define a class or struct with properties for each of your

How to set CssClass on button in DataGrid

人盡茶涼 提交于 2019-12-12 16:02:00
问题 I have a ButtonColumn in a DataGrid: <asp:ButtonColumn HeaderText="Edit" ButtonType="PushButton" Text="Edit" /> How do I set it's CSS class? The only way I can see to do it, is hooking to the RowDataBound event: Protected Sub dgSchedule_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgSchedule.ItemDataBound If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then DirectCast(e.Item.Cells(6).Controls(0),

AcceptChanges() throws exception when changing CheckBox is with space bar

懵懂的女人 提交于 2019-12-12 15:41:40
问题 In my DataGridView I use a DataView to filter the DataTable. The CheckBox value is used in the filter. When the CheckBox is unchecked, the row should disappear. To run that immediately, I use AcceptChanges() in an CurrentCellDirtyStateChanged event. (Otherwise the row stays displayed, until another row is selected). This works when I unselect the checkbox with the mouse. Using the space bar a NullReferenceException exception is thrown. Here is some sample code: (Full working. Needs only Form1

in .Net 4: PInvokeStackImbalance Exception

心不动则不痛 提交于 2019-12-12 15:37:35
问题 I was using the strlen function from msvcrt.dll in a .Net 3.5 project. More specifically: private unsafe static extern int strlen( byte *pByte ); After migrating to .NET 4.0, if I use this function it throws a PInvokeStackImbalance exception. How can I import the .NET 3.5 msvcrt.dll or fix this exception? 回答1: I suspect that the problem is with the calling convention, you should be using Cdecl. [DllImport("msvcrt.dll", CallingConvention=CallingConvention.Cdecl)] private unsafe static extern

IPAddress.[Try]Parse parses 192.168 to 192.0.0.168

断了今生、忘了曾经 提交于 2019-12-12 14:49:41
问题 I have the following scenario: IPAddress ip; IPAddress.TryParse("192.168", out ip); if(ip == null){//do something with IP} I would expect the parsing to fail, instead it is parsed as "192.0.0.168". What am I missing here? (IPAddress.Parse works the same) 回答1: From the documentation of Parse: The number of parts (each part is separated by a period) in ipString determines how the IP address is constructed. A one part address is stored directly in the network address. A two part address,

Network Drive Not Available On Startup

青春壹個敷衍的年華 提交于 2019-12-12 14:36:23
问题 I have a C# application which loads at startup, and logs data to a network drive, which is mounted as X: When the machine first boots, the application throws an error that X:\ is not available. If I restart the app, same error. However, if I open Windows Explorer and double click to browse the drive, I can then run the application and it will connect to X: just fine. Do network drives not automatically initialise on startup, despite being mapped? Is there a way to set them to initialise

.NET REGEX Matching matches empty strings

一曲冷凌霜 提交于 2019-12-12 14:36:11
问题 I have this pattern: [0-9]*\.?[0-9]* Target: X=113.3413475 Y=18.2054775 And i want to match the numbers. It matches find in testing software like http://regexpal.com/ and Regex Coach. But in Dot net and http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx I get: Found 11 matches: 1. 2. 3. 4. 5. 6. 113.3413475 7. 8. 9. 10. 18.2054775 11. String literals for use in programs: C# @"[0-9]*[\.]?[0-9]*" Any one have any idea why i'm getting all these empty matches

MVVM DataGrid copy information from selected cells

百般思念 提交于 2019-12-12 14:35:15
问题 I’m using .Net 4.0 DataGrid with MVVM pattern. I need to enable user to select cells and copy information from selected cells to other DataGrid rows (either via keyboard shortcut or context-menu copy/paste). I tried to achieve this via SelectedItem or sending SelectedItem as CommandParameter but this functions only with the whole row and not with cells. (DataGrid is bound to ObservableCollection that contains objects with float fields. These fields are then mapped to DataGrid cells) So, is

C# GUI Thread Error

狂风中的少年 提交于 2019-12-12 14:14:16
问题 I am developing an application that should receive commands through a socket interface and then execute them in a GUI. This application is being developed in C# .NET 4.0 and it uses WPF for its GUI. The socket interface has a worker thread that keeps listening to the socket and processing its commands, so if for example a Show Popup command is received, the worker thread calls a manager class that is responsible for creating the popup and showing it on the main screen. The manager method that

WCF messageheader vs messagebodymember?

你离开我真会死。 提交于 2019-12-12 13:06:32
问题 I do not understand when I should put the [MessageHeader] instead of the [MessageBodyMember]? I have read that it's used to conform some protocol like Soap, but still, what does it change at the end? 回答1: SOAP is a protocol in which each message (request or response) is made up of two parts: the Header and the Body , inside an Envelope : <s:Envelope xmlns:s='the namespace for the soap version'> <s:Header> <!-- SOAP headers will come here --> </s:Header> <s:Body> <!-- SOAP body members will