|
This does not make it generic because I do not know the name of the item. Method was just an example.
Thanks
|
|
|
|
|
I think you are missing the point.
How are the elements being added to your ArrayList in the first place?
Illogical thoughts make me ill
|
|
|
|
|
They are added to the list collection i.e.
foreach (...)
{
myList.Add(myClass)
}
|
|
|
|
|
so you should check to see if the list already contains myClass before you add it in...
foreach(...)
{
if(!myList.Contains(myClass))
myList.Add(myClass);
}
...not 100% sure the contains will work with a class but worth a try
EDIT: Tested and does NOT work
Illogical thoughts make me ill
|
|
|
|
|
Object reference not set to an instance of an object.
|
|
|
|
|
What are you talking about? Show me what code you have
As I have edited the compare does not work. But it will do if you override the Equals() function is your custom class. For example...
public override bool Equals(object obj)
{
if (obj == null)
return false;
MyClass m = obj as MyClass;
if (m == null)
return false;
return Name == m.Name && Value == m.Value;
}
EDIT: Microsoft recommend the GetHashCode function is also overridden along with the Equals function (see here[^]). Example...
public override int GetHashCode()
{
return Name.GetHashCode() ^ Value;
}
Illogical thoughts make me ill
modified on Tuesday, February 15, 2011 7:37 AM
|
|
|
|
|
Loop over list get items which are duplicate and remove them.
See This as example
|
|
|
|
|
I do not see the example which matches what i am trying to do with the example I sent initially.
Thanks
|
|
|
|
|
As Hum Dum told you, you have to write code: iterating the collection containing the duplicates and create a new collection.
I cannot remember: What did I before google?
|
|
|
|
|
I did as you suggested and it is ok now.
Thank you all.
|
|
|
|
|
Just because it works it doesn't make it right.
It is better to not add the duplicates in the first place then to have to remove them afterwards. There are some instances where this might be acceptable but I imagine your task is not one of these.
Illogical thoughts make me ill
|
|
|
|
|
So you didn't know how to remove duplicates from a collection but you understood HumDum's link to delegates and predicates. Wow, that is awesome.
"You get that on the big jobs."
|
|
|
|
|
HTH (if you do not have to care about performance)
List<string> list = new List<string>();
list.Add("Method");
list.Add("Method");
list.Add("Method2");
list.Add("Method");
List<string> res = (from _ in list group _ by _ into __ select __.Key).ToList();
and here is the sample with the HasSet:
List<string> res = new HashSet<string>(list).ToList();
modified on Tuesday, February 15, 2011 10:14 AM
|
|
|
|
|
Others have pointed possible solutions out to you, but I would suggest that you need to step back and think about what equality actually is. It's not such a simple subject, and it's not something you should rush into. In the case of a string, equality could simply be that the text is the same (taking culture into account). In more complex cases, you need to consider whether equality is based on all values of a class being the same, or only some values.
Building a generic equality tester is a big deal. The closest you might get, for instance, could be to have a method that iterates over the items and uses Compare to compare them. This, then depends on the original items being in an IComparable class. I leave it to you to figure out whether or not it's worth the effort to build something generic, or to allow a degree of specialisation to occur in there.
|
|
|
|
|
Umm, is possible to track the mouse pointer if you move off the form, I have written an app that I needed to track the mouse pointer on the form. Now I am trying to track the mouse pointer out of the Form on the Windows back ground. I think I am having issues attaching the event handler
<
MouseHookProcedure = new HookProc(Form1.MouseHookProc);
hHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProcedure, (IntPtr)0, 0);
>
dont appear to be setting hHook.....
HELP
|
|
|
|
|
Cursor.Position will retrieve current position of the cursor on the screen
good luck
|
|
|
|
|
The simple answer, why oh why did I not think of that. Stick
label1.Text = Cursor.Position.ToString(); in a timer and off you go!
|
|
|
|
|
|
Thanks, I will have a look at that Glenn
|
|
|
|
|
read up on Mouse.Capture
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi,
I want to access port80, I am creating a software which blocks unwanted websites those who are browse from any browser in a system, so I am writing a service in that I am writing a code to access port80 and to get the url to check in my db and allow or diney url. I tried using HttpListener class in c#...but not working...can you help me to get this.
krishna
|
|
|
|
|
You need to get your software between the web browser and the network card. I do not know if you can get a hook in between and filter there. But you can write a proxy server which the browser would then use. Or write a good "proxy.pac" script (e.g. "no-ads.pac": http://www.schooner.com/~loverso/no-ads/[^]).
|
|
|
|
|
you could add unwanted IP adresses to your hosts file...
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
That won't be useful when some sites serve both content and ads. The proxy.pac by Loverso (see link in my post above) circumvents that problem.
|
|
|
|
|
Hello Experts,
I have generate the problem when i am using port no 465 to send mail with the use of Gmail.Code below after some pause raise exception "waiting times operations has expired". Why?
public static void Send(string from, string pwd, string to, string subject,string body)
{
MailMessage message = new MailMessage(from, to);
message.Subject = subject;
message.Body = body;
int port = 465;
SmtpClient client = new SmtpClient("smtp.gmail.com", port);
client.Credentials = new NetworkCredential(from, pwd);
client.EnableSsl = true;
client.Send(message);
}
Thanks
If you can think then I Can.
|
|
|
|