hi
i have problem with my thread threadid is 74379
it is not loading the thread please solve my problem
thank you
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Nilanka DharmadasaPosted Dec 24, 2009, 2:36 AM
You should implment IEquatable interface for that.
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//this is my class
public class LibraryClass : IEquatable
{
#region Fields
int bookId;
string bookName;
string category;
string authorName;
#endregion
#region Properties
public int BookId
{
get { return bookId; }
set { bookId = value; }
}
public string BookName
{
get { return bookName; }
set { bookName = value; }
}
public string Category
{
get { return category; }
set { category = value; }
}
public string AuthorName
{
get { return authorName; }
set { authorName = value; }
}
#endregion
public LibraryClass()
{
}
public LibraryClass(int a, string b, string c, string d)
{
this.BookId = a;
this.BookName = b;
this.category = c;
this.AuthorName = d;
}
public override string ToString()
{
return string.Format("{0,-5}{1,-10}{2,-10}{3,-10}", BookId, BookName, Category, AuthorName);
}
public override bool Equals(object obj)
{
return this.Equals(obj as LibraryClass);
}
public bool Equals(LibraryClass p)
{
// If parameter is null, return false.
if (Object.ReferenceEquals(p, null))
{
return false;
}
// Optimization for a common success case.
if (Object.ReferenceEquals(this, p))
{
return true;
}
// If run-time types are not exactly the same, return false.
if (this.GetType() != p.GetType())
return false;
return (bookName == p.BookName);
}
}
Here, also I check the bookname and if there is a book with the same bookname in the list it will return true for contains. But you can change it as you want.
Now you can call contains method.
LinkedList
obj.AddFirst(new LibraryClass(10, "srinivas", "fds", "dsffdsf"));
obj.AddFirst(new LibraryClass(20, "srini", "ffds", "ddsfsffdsf"));
obj.AddFirst(new LibraryClass(30, "sriniffsf", "ffdfsfds", "dfdsdsfsffdsf"));
foreach (LibraryClass val in obj)
{
Console.WriteLine(val);
}
//Now you create an object with a book name "srini"
LibraryClass temp = new LibraryClass(20, "srini", "ffdsfff", "fdsf");
//Now you check there is an object in the list with the same name.
if (obj.Contains(temp))//returns true as there is a object with same bookname
{
}
If you find my answer useul, please tick 'Do you like this answer' checkbox.
srinivasPosted Dec 23, 2009, 11:28 PM
thank you
Nilanka DharmadasaPosted Dec 23, 2009, 11:25 PM
What do you mean by not loading?
Can you upload your code? Then we can locate the error easily. Btw what happened to your contains problem? I cannot access that thread to post a reply. If it is resolved, then no problem. Otherwise let me know. I have the answer.