聚合问答列表
8 浏览

How to truncate milliseconds off of a .NET DateTime

I'm trying to compare a time stamp from an incoming request to a database stored value. SQL Server of course keeps some precision of milliseconds on the time, and when read into a .NET DateTime, it in...

c#,.net,datetime 2017-11-30
7 浏览

How convert byte array to string [duplicate]

This question already has an answer here: How to convert UTF-8 byte[] to string? 11 answers I created...

c#,bytearray,binaryreader 2017-11-30
11 浏览

Programming P2P application

I am writing a custom p2p program that runs on port 4900. In some cases when the person is behind a router, this port is not accessible from the internet. Is there an automatic way of enabling the a...

c#,.net,sockets,networking,p2p 2017-11-30
AD 友情赞助
6 浏览

LINQ - Left Join, Group By, and Count

Let's say I have this SQL: SELECT p.ParentId, COUNT(c.ChildId) FROM ParentTable p LEFT OUTER JOIN ChildTable c ON p.ParentId = c.ChildParentId GROUP BY p.ParentId How can I translate this into LI...

c#,.net,linq,linq-to-sql 2017-11-30
7 浏览

How does the C# compiler detect COM types?

EDIT: I've written the results up as a blog post. The C# compiler treats COM types somewhat magically. For instance, this statement looks normal... Word.Application app = new Word.Application(); ...

c#,com,compiler-construction,c#-4.0 2017-11-30
5 浏览

Entity Framework 4 - AddObject vs Attach

I have been working with Entity Framework 4 recently, and am slightly confused as to when to use ObjectSet.Attach, and ObjectSet.AddObject. From my understanding: Use "Attach" when an Entity alread...

c#,.net,entity-framework-4,crud 2017-11-30
AD 友情赞助
7 浏览

How do you convert a DataTable into a generic list?

Currently, I'm using: DataTable dt = CreateDataTableInSomeWay(); List<DataRow> list = new List<DataRow>(); foreach (DataRow dr in dt.Rows) { list.Add(dr); } Is there a better/magi...

c#,generics,datatable 2017-11-30
7 浏览

Cannot delete directory with Directory.Delete(path, true)

I'm using .NET 3.5, trying to recursively delete a directory using: Directory.Delete(myPath, true); My understanding is that this should throw if files are in use or there is a permissions problem,...

c#,.net,exception,io 2017-11-30
6 浏览

How can you strip non-ASCII characters from a string? (in C#)

How can you strip non-ASCII characters from a string? (in C#)

c#,ascii 2017-11-30
AD 友情赞助
6 浏览

ASP.NET MVC Conditional validation

How to use data annotations to do a conditional validation on model? For example, lets say we have the following model (Person and Senior): public class Person { [Required(ErrorMessage = "*")] ...

c#,asp.net-mvc,forms,validation 2017-11-30
6 浏览

How to tell whether a point is to the right or left side of a line

I have a set of points. I want to separate them into 2 distinct sets. To do this, I choose two points (a and b) and draw an imaginary line between them. Now I want to have all points that are left fro...

c#,math,geometry,convex-hull 2017-11-30
6 浏览

Is the C# static constructor thread safe?

In other words, is this Singleton implementation thread safe: public class Singleton { private static Singleton instance; private Singleton() { } static Singleton() { instan...

c#,multithreading,singleton 2017-11-30
AD 友情赞助
7 浏览

How can I make a .NET Windows Forms application that only runs in the System Tray?

What do I need to do to make a Windows Forms application run in the System Tray? Not an application that can minimize to the tray, but one that exists only in the tray, with nothing more than an icon...

c#,.net,winforms,system-tray 2017-11-30
7 浏览

Passing arguments to C# generic new() of templated type

I'm trying to create a new object of type T via its constructor when adding to the list. I'm getting a compile error: The error message is: 'T': cannot provide arguments when creating an instance...

c#,.net,generics,new-operator 2017-11-30
7 浏览

Why do we need boxing and unboxing in C#?

Why do we need boxing and unboxing in C#? I know what boxing and unboxing is, but I can't comprehend the real use of it. Why and where should I use it? short s=25; object objshort=s; //Boxing sho...

c#,.net,boxing 2017-11-30
7 浏览

Most common C# bitwise operations on enums

For the life of me, I can't remember how to set, delete, toggle or test a bit in a bitfield. Either I'm unsure or I mix them up because I rarely need these. So a "bit-cheat-sheet" would be nice to hav...

c#,.net,enums,bit-manipulation,flags 2017-11-30
6 浏览

Deserializing JSON into an object

I have some JSON: { "foo" : [ { "bar" : "baz" }, { "bar" : "qux" } ] } And I want to deserialize this into a collection. I have defined this class: public class Foo { ...

c#,json,json.net 2017-11-30
6 浏览

Entering keys manually with Entity Framework

I'm trying to use Entity Framework code first for a simple database project and I run into a problem I simply cannot figure out. I noticed EF was setting the ID for my tables automatically increasin...

c#,asp.net,sql,entity-framework 2017-11-30
7 浏览

TAP global exception handler

This code throws an exception. Is it possible to define an application global handler that will catch it? string x = await DoSomethingAsync(); Using .net 4.5 / WPF

c#,.net,exception,task-parallel-library,async-await 2017-11-30
8 浏览

How to change menu hover color

How to change the Hover (mouse over) color of a Windows application menu? Any method in C# ? OR Any way by using Windows API (DllImport) ? See image :

c#,winforms,winapi 2017-11-30
AD 友情赞助