Skip to main content
Filter by
Sorted by
Tagged with
210 votes
9 answers
181k views

I have become painfully aware of just how often one needs to write the following code pattern in event-driven GUI code, where private void DoGUISwitch() { // cruisin for a bruisin' through ...
Tom Corelis's user avatar
  • 5,060
23 votes
1 answer
17k views

Using user32.dll and C# I wrote the method that you see below. Using a process handle for a window, it will set the window position at a provided (x, y) location. However, in a multi-monitored ...
sapbucket's user avatar
  • 7,265
322 votes
7 answers
207k views

I came across some code that said public int MaxHealth => Memory[Address].IsValid ? Memory[Address].Read<int>(Offs.Life.MaxHp) : 0; Now I am somewhat familiar ...
Mike's user avatar
  • 6,090
174 votes
4 answers
12k views

IEnumerable<T> is co-variant but it does not support value type, just only reference type. The below simple code is compiled successfully: IEnumerable<string> strList = new List<string&...
cuongle's user avatar
  • 75.5k
419 votes
10 answers
448k views

I would like to run an external command line program from my Mono/.NET app. For example, I would like to run mencoder. Is it possible: To get the command line shell output, and write it on my text ...
stighy's user avatar
  • 7,370
142 votes
18 answers
97k views

I try to migrate from Newtonsoft.Json to System.Text.Json. I want to deserialize abstract class. Newtonsoft.Json has TypeNameHandling for this. Is there any way to deserialize abstract class via ...
SkyStorm's user avatar
  • 1,523
107 votes
8 answers
132k views

I need a regex that will only find matches where the entire string matches my query. For instance if I do a search for movies with the name "Red October" I only want to match on that exact title (...
Micah's user avatar
  • 117k
17 votes
2 answers
13k views

So, following this, I decided to explicitly instantiate a COM object on a dedicated STA thread. Experiments showed that the COM object needed a message pump, which I created by calling Application.Run(...
bavaza's user avatar
  • 11.1k
968 votes
27 answers
1.6m views

If I have these strings: "abc" = false "123" = true "ab2" = false Is there a command, like IsNumeric() or something else, that can identify if a string is a valid number?
Gold's user avatar
  • 62.9k
420 votes
13 answers
207k views

C# 2008 I have been working on this for a while now, and I am still confused about the use of finalize and dispose methods in code. My questions are below: I know that we only need a finalizer while ...
ant2009's user avatar
  • 22.7k
317 votes
29 answers
645k views

I have few methods that returns different Generic Lists. Exists in .net any class static method or whatever to convert any list into a datatable? The only thing that i can imagine is use Reflection ...
Josema's user avatar
  • 4,748
131 votes
6 answers
313k views

I have a class and when I try to use it in another class I receive the error below. using System; using System.Collections.Generic; using System.Linq; namespace MySite { public class Reminders ...
GibboK's user avatar
  • 74.2k
333 votes
9 answers
402k views

What is the purpose of the Using block in C#? How is it different from a local variable?
Ryan Michela's user avatar
  • 8,414
421 votes
24 answers
394k views

How to recursively list all the files in a directory and child directories in C#?
user avatar
111 votes
18 answers
95k views

If I have a string with a valid math expression such as: String s = "1 + 2 * 7"; Is there a built in library/function in .NET that will parse and evaluate that expression for me and return the result?...
Guy's user avatar
  • 67.7k
2923 votes
13 answers
441k views

What are the correct version numbers for C#? What came out when? Why can't I find any answers about C# 3.5? This question is primarily to aid those who are searching for an answer using an incorrect ...
447 votes
18 answers
575k views

To create a new event handler on a control you can do this c.Click += new EventHandler(mainFormButton_Click); or this c.Click += mainFormButton_Click; and to remove an event handler you can do this ...
Carrick's user avatar
  • 4,563
270 votes
16 answers
341k views

I have a class which looks like this: public class Field { public string FieldName; public string FieldType; } And an object List<Field> with values: {"EmployeeID","int"}, {"...
ashwnacharya's user avatar
  • 14.9k
4419 votes
35 answers
1.1m views

How can you enumerate an enum in C#? E.g., the following code does not compile: public enum Suit { Spades, Hearts, Clubs, Diamonds } public void EnumerateAllSuitsDemoMethod() { ...
Ian Boyd's user avatar
  • 259k
586 votes
7 answers
439k views

In a verbatim string literal (@"foo") in C#, backslashes aren't treated as escapes, so doing \" to get a double quote doesn't work. Is there any way to get a double quote in a verbatim string literal? ...
kdt's user avatar
  • 28.6k
412 votes
14 answers
150k views

According to the documentation of the == operator in MSDN, For predefined value types, the equality operator (==) returns true if the values of its operands are equal, false otherwise. For ...
Hosam Aly's user avatar
  • 42.6k
124 votes
13 answers
228k views

Is there a function the .NET framework that can evaluate a numeric expression contained in a string and return the result? F.e.: string mystring = "3*(2+4)"; int result = EvaluateExpression(mystring);...
sindre j's user avatar
  • 4,444
59 votes
3 answers
46k views

I've translated my mvc website, which is working great. If I select another language (Dutch or English) the content gets translated. This works because I set the culture in the session. Now I want to ...
juFo's user avatar
  • 18.7k
675 votes
19 answers
416k views

Using reflection, how can I get all types that implement an interface with C# 3.0/.NET 3.5 with the least code, and minimizing iterations? This is what I want to re-write: foreach (Type t in this....
juan's user avatar
  • 82.3k
302 votes
13 answers
873k views

How can I populate my C# object with the JSON object passed via AJAX? This is the JSON object passed to a C# web method from the page using JSON.stringify: { "user": { "name&...
MHop's user avatar
  • 3,133

1
3 4
5
6 7
3566