Questions

Drawing text in .NET

I'm doing some tests about drawing text in .Net and I had the following results. ![Drawing text example](https://i.stack.imgur.com/bRcps.png) - `FlatStyle``System`- [Graphics.DrawString()](http://ms...

1 Sep at 10:29

Get all pairs in a list using LINQ

How do I get all possible pairs of items in a list (order not relevant)? E.g. if I have ``` var list = { 1, 2, 3, 4 }; ``` I would like to get these tuples: ``` var pairs = { new Tuple(1, 2), ...

3 May at 18:57

C#: SQL Query Builder Class

Where can I find a good SQL Query builder class. I just need a simple class to build a SQL string and that is it. I will need it for C# and MySql. I really don't need anything like Linq or NHibernate....

24 Aug at 07:38

Is `Request.IsLocal` secure?

Is the property `Request.IsLocal` spoofable, or 100% trustworthy? I want to be certain a request is coming from my box only.

17 Jan at 18:58

Programmatically rename open file on Windows

I am porting a Unix C application to Windows. This application renames files while they are open, which is perfectly fine on Unix but apparently it does not work on Windows. Tracing all the renames to...

22 Aug at 15:17

High resolution timer

I want to have a timer with about 5millisecond resolution. but the current Timer in .Net has a resolution of about 50ms. I could not find any working solution that creates a high resolution timer, al...

7 Feb at 10:23

Algorithm to calculate nearest location based on longitude & latitude

I am currently trying to develop an algorithm to calculate which known locations are closest to current known location. I have a list of say 100 known locations (meaning I have both long- and latitud...

Error: An expression tree may not contain a dynamic operation

I use Asp.Net 4 and C#, I use EF 4. I have this query, I receive an error: ``` An expression tree may not contain a dynamic operation ``` --- ``` dynamic o = e.Item.DataItem; var imagesContent...

19 Aug at 07:56

Unit Test Description question

There is a description entry for Unit Tests in Visual Studio. Is it possible to modify a test description after creation?

Current date and time - Default in MVC razor

When the MVC view page with this textbox, loads , I would like to display current date and time by default. How can I do this? in razor. ``` @Html.EditorFor(model => model.ReturnDate) ```

Union multiple number of lists in C#

I am looking for a elegant solution for the following situation: I have a class that contains a List like ``` class MyClass{ ... public List<SomeOtherClass> SomeOtherClassList {get; set;} ... } ``...

4 Aug at 21:13

WPF: how do i handle a click on a ListBox item?

In my WPF app I'm handling a ListBox SelectionChanged event and it runs fine. Now I need to handle a click event (even for the already selected item); I've tried MouseDown but it does not work. How c...

11 Jan at 07:7

B-Trees / B+Trees and duplicate keys

I'm investigating the possibility of putting together a custom storage scheme for my application. It's worth the effort of potentially reinventing the wheel, I think, because both performance and sto...

19 Aug at 20:32

#If DEBUG is ignored (VB.net or C#)

I have several of these in my code which have been working fine so far: ``` #If DEBUG Then ... some code here #End If ``` Now, i am noticing that, lately, the code inside the " #If DE...

2 Aug at 12:48

Sending data to USB printer in C#?

I have script code for zebra TLP2844 printer in a text file. I need to print that script file to a printer connected via USB. I executed that script using parallel port by using DOS command: ``` /c ...

7 Aug at 09:10

C# : change listbox items color

i am working on program on windows forms I have a listbox and I am validating data I want the correct data be added to the listbox with color green while the invalid data added with red color and I al...

1 Aug at 09:12

Using TypeBuilder to create a pass-through constructor for the base class

Say I have a `SpaceShip` class, like so: ``` public class SpaceShip { public SpaceShip() { } public SpaceShip(IRocketFuelSource fuelSource) { } } ``` I want to use [TypeBuilder](http://ms...

19 Oct at 03:35

Boolean Property Getter and Setter Locking

Is there any reason why you would create locks around the getter and setter of a boolean property like this? ``` private _lockObject = new object(); private bool _myFlag; public bool MyFlag { ...

29 Jul at 13:33

Do C# try-finally CERs break in iterators?

Apparently, Constrained Execution Region guarantees do not apply to iterators (probably because of how they are implemented and all), but is this a bug or by design? [See the example below.] i.e. Wha...

23 May at 12:19

How to use System.Lazy with Setter to Lazy Initialization of List in POCO Entities?

I want to use System.Lazy to Lazy Initialization of my List in my Entites: ``` public class Questionary { private Lazy<List<Question>> _questions = new Lazy<List<Question>>(() => new List<Questio...

When is a .NET namespace implemented by a .NET Framework component?

(Yet another question from my "Clearly I'm the only idiot out here" series.) When I need to use a class from the .NET Framework, I dutifully look up the documentation to determine the corresponding n...

27 Jul at 17:30

How can I limit the length of a string to 150 characters?

I tried the following: ``` var a = description.Substring(0, 150); ``` However this gives a problem if the length of description is less than 150 chars. So is there another way I can limit the lengt...

26 Jul at 16:16

MyClass equivalent in C#

In looking at [this question](https://stackoverflow.com/questions/6830825/shared-class-field-in-visual-basic), commenter @Jon Egerton mentioned that `MyClass` was a keyword in `VB.Net`. Having never u...

23 May at 12:24

Does iteratee I/O make sense in non-functional languages?

In Haskell, [Iteratee based I/O](http://www.haskell.org/haskellwiki/Iteratee_I/O) seems very attractive. Iteratees are a composable, safe, fast ways of doing I/O inspired by the 'fold' a.k.a. 'reduce'...

22 Jul at 20:6

how to make a webbrowser control go blank in c#?

Initially when the webbrowser is just loaded onto a form , it is blank(ie white color) . Once we go to a particular website , is there a way to make it go blank again . I tried going through the me...

9 Sep at 16:15