.net-2.0

Downsides to using Int64 universally instead of int (C#)

We use a base entity with properties such as version (datetime needed for NHibernate) and guid (as key). It also has an Id (int) field with two functions. Firstly to relate to legacy application key if there is one. Secondly as a shorthand code: for instance files are sometimes created based on these which would look ugly and long usi...

Strongly Typed Resources Causing Problems?

In the middle of some refactoring and I've moved a resources file from one project to another. I think I clicked a warning telling me to Strongly type the resource file at one point and now I'm getting: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MyProject.Common.Resour...

Is there an alternative to string.Replace that is case-insensitive?

I need to search a string and replace all occurances of %FirstName% and %PolicyAmount% with a value pulled from a database. The problem is the capitalization of FirstName varies. That prevents me from using the String.Replace() method. I've seen web pages on the subject that suggest Regex.Replace(strInput, strToken, strReplaceWith, Rege...

How to do forward-compatibility for .NET 3.5 features in .NET 2.0 apps?

I want to start using .NET 3.5 features in an app that is currently stuck in the past - how can I write in support for selected features like JSON serialization in a forward-compatible way? In the case of JSON serialization I need to reference System.ServiceModel.Web - is it OK to reference a .NET 3.5 dll in a VS2005 app? Presumably thi...

.Net Equivalent of set_unexpected()

Is there a .net equivalent to the C++ unexpected()/set_unexpected() functionality? Edit: Sorry--I omitted some details previously: Language: C# 2.0 I have some legacy apps that seem to be throwing some unhandled exception somewhere. I just want to put something in place to stop the customer's pain until I can trace the actual sour...

Which of these two GetLargestValue C# implementations is better, and why?

I'm having a disagreement with someone over how best to implement a simple method that takes an array of integers, and returns the highest integer (using C# 2.0). Below are the two implementations - I have my own opinion of which is better, and why, but I'd appreciate any impartial opinions. Option A public int GetLargestValue(int[] v...

What is new in Visual Studio 2008 vs 2005 or C# 3.0 vs C# 2.0?

I was browsing the Hidden Features of C# question and thought I would try out one of the features I was unfamiliar with. Unfortunately I use Visual Studio 2005 and the feature in question was introduced later. Is there a good list for new features in C# 3.0 (Visual Studio 2008) vs. C# 2.0 (Visual Studio 2005)? ...

split xml document into chunks

I have a large xml document that needs to be processed 100 records at a time It is being done within a Windows Service written in c#. The structure is as follows : <docket xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="docket.xsd"> <order> <Date>2008-10-13</Date> <orderNumber>050758...

Changing Output path of the Unit Test project in Visual Studio 2008

I changed the output path of the test project, because the default path doesn't conform to our projects directory structure. After I did that, Visual Studio 2008 fails to run the tests, because it can't find the Unit Test project assembly. What else do I have to change for the Unit Test Engine to find the assembly? ...

Restrict adding control on Panel

How can i restrict adding controls in Panel in C# window controls? I have to restrict user to add controls in a panel at design time. ...

C# 2.0 Threading Question (anonymous methods)

I have a simple application with the following code: FileInfo[] files = (new DirectoryInfo(initialDirectory)).GetFiles(); List<Thread> threads = new List<Thread>(files.Length); foreach (FileInfo f in files) { Thread t = new Thread(delegate() { Console.WriteLine(f.FullName); }); thread...

Best way to get a comma delineated string into xml format?

Using VB.net (.net 2.0) I have a string in this format: record1_field1,record1_field2,record2_field3,record2_field1,record2_field2, etc... I wonder what the best (easiest) way is to get this into an xml? I can think of 2 ways: Method 1: - use split to get the items in an array - loop through array and build an xml string using conc...

Databinding DropDown Control in .Net

I am binding the dropdown with db entity. ddlCustomer.DataSource = Customer.GetAll(); ddlCustomer.DataTextField = "CustomerName"; ddlCustomer.DataBind(); I want to add "SELECT" as the first itemlist in dropdown and bind then entity to the dropdown. How can i do this? ...

Streaming directly to a database

I'm using c#, and have an open tcpip connection receiving data. Is it possible to save the stream to an ms sql server database as I'm receiving it, instead of receiving all the data then saving it all? If the stream could be sent to the database as it's being received, you wouldn't have to keep the entire chunk of data in memory. Is t...

Localization: How to map culture info to a script name or Unicode character range?

I need some information about localization. I am using .net 2.0 with C# 2.0 which takes care of most of the localization related issues. However, I need to manually draw the alphabets corresponding to the current culture on the screen in one particular screen. This would be similar to the Contacts screen in Microsoft Outlook (Address Ca...

Best tools for testing bulk emailing in .net?

Scenario is that we send out thousands of emails through SMTP server. Content is created in advance and picked up when sent. The thing is we want to find where our bottlenecks are in production environment and where work needs to be done. Goal is to be able to send half a million emails in ten minutes*. Should we create dummy email...

Getting key of value of a generic Dictionary?

It's easy to get the value of a key from a .Net 2.0 generic Dictionary: Dictionary<int, string> greek = new Dictionary<int, string>(); greek.Add(1, "Alpha"); greek.Add(2, "Beta"); string secondGreek = greek[2]; // Beta But is there a simple way to get the key of a value? int[] betaKeys = greek.WhatDoIPutHere("Beta"); // expecting s...

Serialize in a human readable text format

Is there a way in .NET 2.0 (C#) to serialize object like you do using XmlSerializer in a simple / customizable human readable format thats for instance looks like PXLS or JSON? Also I know that XML is human readable, I'm looking for something with less annoying redundancy, something that you can output to the console as a result for the ...

Phone number normalization: Any pre-existing libraries?

I have a system which is using phone numbers as unique identifiers. For this reason, I want to format all phone numbers as they come in using a normalized format. Because I have no control over my source data, I need to parse out these numbers myself and format them before adding them to my DB. I'm about to write a parser that can read ...

C# NullReference Exception and ReSharper suggestion

This is what I have written: if ((lstProperty[i].PropertyIdentifier as string).CompareTo("Name") == 0) Resharper put me an error (I am new with ReSharper... I am trying it) and it suggests me : if (((string) lstProperty[i].PropertyIdentifier).CompareTo("Name") == 0) Why is the second is NullException safe? For me both will crash ...