C# .NET - Help with generic list

Asked By John O'Hara
09-Feb-10 11:12 AM

I have a generic list which contains a class called Parameter.

Parameter contains 2 integers, ParamType and ParamValue.

A generic list is built containing a small number of values List<Parameter> myList

I have created a function which passes in 2 parameters.  These are passed individually but are used to create a new Parameter within the function.  The Parameter is tested against myList, and if it is found removed.

In order to do this I have used the remove function, the syntax being:

myList.Remove( new Parameter(ParamType, ParamValue));

The remove isn't working and at present I'm using LINQ to do it.  I would apprecaite it if someone could point out the error with the remove function so that I can correctly code it without LINQ.

Thanks

John

Sorry, posted with wrong account.  I don't believe your code will work  Sorry, posted with wrong account. I don't believe your code will work

09-Feb-10 11:20 AM
myList.Remove( new Parameter(ParamType, ParamValue));

is testing against a newly created object that doesn't have a reference pointer to an item that actually exists in your list.
  Huggy Bear replied to John O'Hara
09-Feb-10 11:53 PM
Yes Robbe is spot on. You are storing a different instance and while removing you are passing another, this will not work.

But how about using a Generic Dictionary instead of List, here you will get the benefit of key value stuff while storing the parameter class object form the key based on the two parameter values, like

//use this key while storing
string key = string.Format("{0}{1}", param1, param2);

//while removing form the key based on the parameter values again
dictionaryObject.Remove(key);


Create New Account
help
Aryan Hi, Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind methods that are actually defined in a type. The most common extension methods are the LINQ standard query operators that add query functionality to the existing System.Collections . IEnumerable and System To use the standard query operators, first bring them into scope with a using System.Linq directive. Then any type that implements IEnumerable ( T ) appears to have instance methods such as not a requirement for extension methods. They allow you to extend an existing type with new functionality, without having to sub-class or recompile the old type. For instance, you might like to know whether a certain whole lot of those kind of functions, you would put them together in a utility class, like this: public class MyUtils { public static bool IsNumeric( string s) { float output; return float .TryParse(s, out output Yes" ); else Console.WriteLine( "No" ); However, with Extension Methods, you can actually extend the String class to support this directly. You do it by defining a static class, with a set
namespaces causes the validation error template not to appear in the UI so I always remove these namespaces when I notice that they are not in use. The XAML Organizer add the add-in. Figure 1. XAML Organizer Screenshot This add-in can do the following: remove unused namespaces, sort attributes, and fix format. It is important to note that each command only works when the XAML is valid because I used LINQ to XML to parse the XAML. To better understand what these commands do, let’s try to use the add-in on the following XAML code. < Window x:Class = "WpfApplication.MainWindow" xmlns = "http: / / schemas.microsoft.com / winfx / 2006 / xaml / presentation" xmlns:x = "http: / / schemas Width = "120"> RadioButton < / RadioButton > < / ScrollViewer > < / Grid > < / Window > Listing 1. XAML Code Example First, let’s remove unused namespaces. In the preceding listing, the namespace clr-namespace:WpfApplication named local is not used. Clicking on the Removed Unused Namespaces menu item yields the following XAML. < Window x:Class = "WpfApplication.MainWindow" xmlns = "http: / / schemas.microsoft.com / winfx / 2006 / xaml / presentation" xmlns:x = "http: / / schemas namespaces in the root element. Another important thing to note is that this command might remove a namespace declaration that is in use if there are two or more namespace declarations
started, became idle, and is persisted to the database. Then, you realize that the Order class should have another property to address some defect. I believe that implementing side by side machine workflow that is hosted as a WCF service. This workflow contains 4 states: Initial, New, Processed, and Completed. The service interface provides 3 operations: CreateOrder, ProcessOrder, and CloseOrder. Each operation is implemented by a ReceiveActivity in the workflow. When we click on the New Order button, the workflow is started and an Order object is assigned to a property of the workflow. The current state is then set to the New state. In our WPF application, the current state is distinguished by the thick black border the serialized data. This data is in binary form because the SqlWorkflowPersistenceService uses the BinaryFormatter class for serialization and deserialization. Type and Assembly Changes Making changes to an assembly name or the namespace or name of a type. In our example, the workflow uses an Order class, which is shown below. namespace DataTransferObjects { [Serializable] [DataContract] public class Order { [DataMember] public int Id { get; set; } [DataMember] public string Customer { get; set; } } } Listing 1. Order Class This class is defined in the DataTransferObjects assembly. Let’s say we decided to sign