Skip to main content
Filter by
Sorted by
Tagged with
161 votes
8 answers
339k views

Is there a simple out of the box way to impersonate a user in .NET? So far I've been using this class from code project for all my impersonation requirements. Is there a better way to do it by using ...
ashwnacharya's user avatar
  • 14.9k
-2 votes
1 answer
2k views

Well, this is the situation... I have a element (<h2 id="test"></h2>) in Page1.aspx, and I want to change it from Page2.aspx (administration zone for the user...), kind of... test....
Kenzo_Gilead's user avatar
  • 2,479
430 votes
14 answers
302k views

There is an entity type called Product that is generated by entity framework. I have written this query public IQueryable<Product> GetProducts(int categoryID) { return from p in db.Products ...
Ghooti Farangi's user avatar
221 votes
9 answers
175k views

I was wondering if it is possible to save C# code fragments to a text file (or any input stream), and then execute those dynamically? Assuming what is provided to me would compile fine within any Main(...
esac's user avatar
  • 24.8k
1042 votes
7 answers
655k views

I keep seeing people using doubles in C#. I know I read somewhere that doubles sometimes lose precision. My question is when should a use a double and when should I use a decimal type? Which type is ...
Soni Ali's user avatar
  • 19.1k
786 votes
36 answers
522k views

Is there some easy way to handle multiple submit buttons from the same form? For example: <% Html.BeginForm("MyAction", "MyController", FormMethod.Post); %> <input type="submit" value="Send" ...
Spoike's user avatar
  • 122k
66 votes
9 answers
536k views

I'm trying to write code that returns whether or not a given integer is divisible evenly by 1 to 20, but I keep receiving the following error: error CS0161: 'ProblemFive.isTwenty(int)': not all ...
user115185's user avatar
232 votes
32 answers
547k views

Is there a free or open source library to read Excel files (.xls) directly from a C# program? It does not need to be too fancy, just to select a worksheet and read the data as strings. So far, I've ...
dbkk's user avatar
  • 12.9k
656 votes
14 answers
562k views

What I want to achieve is very simple: I have a Windows Forms (.NET 3.5) application that uses a path for reading information. This path can be modified by the user, by using the options form I ...
Fueled's user avatar
  • 8,816
50 votes
2 answers
11k views

I have an MVC application that displays a value. This is the controller: public ActionResult Index(DataSites DataSiteList) { if (DataSiteList.Latitude != null) { DataSites test = new ...
Adrien Tancrez's user avatar
1676 votes
24 answers
1.9m views

I have a class called Order which has properties such as OrderId, OrderDate, Quantity, and Total. I have a list of this Order class: List<Order> objListOrder = new List<Order>(); ...
Shyju's user avatar
  • 220k
419 votes
18 answers
91k views

When programming interfaces, I've found I'm doing a lot of casting or object type conversion. Is there a difference between these two methods of conversion? If so, is there a cost difference or how ...
Frank V's user avatar
  • 25.5k
182 votes
5 answers
196k views

I have an FFT result. These are stored in two double arrays: a real part array and an imaginary part array. How do I determine the frequencies that correspond to each element in these arrays? In ...
Rango's user avatar
  • 2,096
229 votes
11 answers
178k views

In a metro app, I need to execute a number of WCF calls. There are a significant number of calls to be made, so I need to do them in a parallel loop. The problem is that the parallel loop exits ...
Darthg8r's user avatar
  • 12.7k
2374 votes
41 answers
1.2m views

How do I convert a string to a byte[] in .NET (C#) without manually specifying a specific encoding? I'm going to encrypt the string. I can encrypt it without converting, but I'd still like to know ...
Agnel Kurian's user avatar
  • 59.9k
1145 votes
28 answers
1.3m views

How do I find the application's path in a console application? In Windows Forms, I can use Application.StartupPath to find the current path, but this doesn't seem to be available in a console ...
JSmyth's user avatar
  • 12.2k
1655 votes
31 answers
381k views

When should you use struct and not class in C#? My conceptual model is that structs are used in times when the item is merely a collection of value types. A way to logically hold them all together ...
Alex Baranosky's user avatar
934 votes
13 answers
1.1m views

I have several methods all with the same parameter types and return values but different names and blocks. I want to pass the name of the method to run to another method that will invoke the passed ...
user31673's user avatar
  • 13.7k
932 votes
21 answers
958k views

What are all the array initialization syntaxes that are possible with C#?
Joshua Girard's user avatar
541 votes
17 answers
593k views

How do I execute a command-line program from C# and get back the STD OUT results? Specifically, I want to execute DIFF on two files that are programmatically selected and write the results to a text ...
Wing's user avatar
  • 6,138
37 votes
2 answers
30k views

On this link, in remarks section it's mentioned that: TypeNameHandling should be used with caution when your application deserializes JSON from an external source. Incoming types should be validated ...
donkey's user avatar
  • 513
953 votes
29 answers
838k views

Is there a way to get the path for the assembly in which the current code resides? I do not want the path of the calling assembly, just the one containing the code. Basically my unit test needs to ...
George Mauer's user avatar
283 votes
12 answers
1.0m views

I have some code and when it executes, it throws a IOException, saying that The process cannot access the file 'filename' because it is being used by another process What does this mean, and ...
Adriano Repetti's user avatar
235 votes
8 answers
492k views

I have date and time in a string formatted like that one: "2011-03-21 13:26" //year-month-day hour:minute How can I parse it to System.DateTime? I want to use functions like DateTime.Parse() or ...
Hooch's user avatar
  • 29.8k
1871 votes
4 answers
124k views

When using lambda expressions or anonymous methods in C#, we have to be wary of the access to modified closure pitfall. For example: foreach (var s in strings) { query = query.Where(i => i.Prop ...
StriplingWarrior's user avatar