.net

What is the special case with the foreach loop that eliminates bounds checking?

What is the special case with the foreach/for loop that eliminates bounds checking? Also which bounds checking is it? ...

Is there a C# case insensitive equals operator?

I know that the following is case sensitive: if (StringA == StringB) { So is there an operator which will compare two strings in an insensitive manner? ...

Can I use <asp:dataGrid> pager with database paging performance?

I have a store procedure that handles paging at database level, receiving @PageSize and @PageIndex. I can create another to return @PageCount, given a page size. Can I make a datagrid do paging at database level without having to develop it outside the control, using the control pager? It seems default use of datagrid paging receives a...

Looking for a Command Line Argument Parser for .NET

I'm looking for a command line argument parser, such as "Command line parser" from http://www.sellsbrothers.com/tools/Genghis/ . Features I'm looking for: Auto-generation of usage Should able to check required and optional parameters Parameters should support IEnumerable with separator support Should support flag parameters Would be n...

.NET: How do I tell if an encoding supports all the chars in my string?

I've got lots of text that I need to output, which includes all sorts of characters from many languages. Sometimes I need to output the text in character encodings other than Unicode (eg, Shift-JIS, or ISO-8859-2), in order to match the page it's going to. If the text has characters that the encoding can't handle (eg, Japanese character...

LINQ to SQL deployment problem

Hi all I have an asp.net application developed. It uses LINQ to SQL to access database, using the .dbml designer in Visual Studio 2008. We are installing the application on client, and they have decided to change the database name on their servers. Now, the application does not work because LINQ can't find the database information. This...

Resizing an image with alpha channel

I am writing some code to generate images - essentially I have a source image that is large and includes transparent regions. I use GDI+ to open that image and add additional objects. What I want to do next is to save this new image much smaller, so I used the Bitmap constructor that takes a source Image object and a height and width, ...

What new functionality is available through delegates and events in C# 3?

I feel that I am not utilizing all the features of delegates/events available in .NET 3.5 and beyond. And more or less still using delegates power available in 2.0. I would appreciate if you tell me how delegates/events should be used now, tricks, short-cuts. Thanks. EDIT Jon suggested his publication on this subject, and I am post...

How to properly name a class with respect to its namespace?

One can often see class names carrying a reference to the namespace to which they belong. One of the most popular examples is the .NET 'Xml' namespace where every single class defined in it is prefixed with the 'Xml' tag. This has always seemed pretty redundant to me, but recently I've realized that in some cases it could be useful... b...

What is wrong with this regular expression?

This regular expression: <IMG\s([^"'>]+|'[^']*'|"[^"]*")+> seems to process endlessly when given this text <img src=http://www.blahblahblah.com/houses/Images/ single_and_multi/roof/feb09/01_img_trrnjks_vol2009.jpg' /> I would expect it to - not find a match (quickly) - because there is only one single quote in the text. I have ...

BCC never sent from Exchange 2007 using SpecifiedPickupDirectory

I'm using an Exchange 2007 pickup directory to send emails from my ASP.NET application with System.Net.Mail.SmtpClient. Thus I'm using SmtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory. It sends emails fine, but then I noticed that BCC is not working at all. The file being placed in the pickup folder seems to have t...

.NET Object size

What is the size of a heap-allocated Object in .net, including management overhead? I'm assuming Objects are allocated along 4-byte boundaries, or is a different approach used? ...

Short-lived objects

What is the overhead of generating a lot of temporary objects (i.e. for interim results) that "die young" (never promoted to the next generation during a garbage collection interval)? I'm assuming that the "new" operation is very cheap, as it is really just a pointer increment. However, what are the hidden costs of dealing with this te...

Does adding a method to a WCF ServiceContract break existing clients?

We have an existing ServiceContract [ServiceContract(Namespace = "http://somesite.com/ConversationService")] public interface IConversationService { [OperationContract(IsOneWay = true)] void ProcessMessage(Message message); [OperationContract(IsOneWay = true)] void ProcessMessageResult(MessageResult resu...

.NET WPF XAML Namespace Mapping for Enum types

I'm binding a collection of my W3CErrorOrWarning type objects to controls in a WPF Window. One of its properties is named "Type". It is of type W3CErrorOrWarningType which is a simple Enum: Enum W3CErrorOrWarningType ValidationError ValidationWarning End Enum I'm trying to use it in this way... <Window ... xmlns:en...

How to use a custom configuration class for web.config with Linq dbml classes

I have a web project that uses a custom configuration class to store app settings in web.config. I do this to be able to store and access configuration settings in web.config that are based on server name. That way when the project moves from development, to staging, to production, I don't have to remember to change the web.config s...

How does the IDisposable interface work?

I understand that it is used to deallocate unmanaged resources, however, I am confused as to when Dispose is actually called. I know it is called at the end of a using block, but does it also get invoked when the object is garbage collected? ...

.NET WPF XAML "BindingExpression path error: ... property not found"

I was trying to bind a collection of my W3CError type objects to a WPF ListView control. It was a nice little 13 line class... Class W3CError Public Type As ErrorOrWarning Public Line As Integer Public Col As Integer Public Message As String Public MessageId As String Public Explanation As String Public So...

Equivalent to SoftReference in .net?

I am familiar with WeakReference, but I am looking for a reference type that is cleared only when memory is low, not simply every time when the gc runs (just like Java's SoftReference). I'm looking for a way to implement a memory-sensitive cache. ...

FileUpload - Verifying that an actual file was uploaded

I have a FileUpload control (FileUpload1) on my web form, as well as a "Sumbit" button, a label, and a hidden field that contains a UserID. I have the following code in the button's click event: string path = Server.MapPath("~/userfiles/"); if (FileUpload.HasFile) { try { FileUpload1.SaveAs(path + UserID.Value + "/imag...