473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

generic list copy

1
i am doing this
public class Books
{
public List<Book> listbook = null;
public Books()
{
listbook = new List<Book>();
}
public void insert(Book p)
{
listbook.Add(p);
}
}
class query<Book> : Books
{
public List<Book> execute()
{
List<Book> newlist = listbook.ToList();
return newlist;
}
}
it gives error
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<gen_code.Book>' to 'System.Collections.Generic.List<Book>' C:\Users\nasir87us\AppData\Local\Temporary Projects\PAQL\gen_code.cs 77 32 PAQL
Jan 22 '12 #1
2 2220
Joseph Martell
198 Expert 128KB
I believe that your problem is hidden by the fact that you have used the name "Book" in your generic class declaration.

This declaration:
Expand|Select|Wrap|Line Numbers
  1. class query<Book> : Books
  2. {
  3.     public List<Book> execute()
  4.     {
  5.         List<Book> newlist = listbook.ToList();
  6.         return newlist;
  7.     }
  8. }
  9.  
creates a generic class using the name "Book" as a place holder for whatever class someone uses when they declare an instance of your query class. It does NOT mean that your generic class is using the Book class. In your class definition, you could replace "Book" with "T" and the following would be the result:
Expand|Select|Wrap|Line Numbers
  1. class query<T> : Books
  2. {
  3.     public List<T> execute()
  4.     {
  5.         List<T> newlist = listbook.ToList();
  6.         return newlist;
  7.     }
  8. }
  9.  
The error is saying that this line:
Expand|Select|Wrap|Line Numbers
  1. List<T> newlist = listbook.ToList();
  2.  
is causing a conversion error because there is no defined conversion between listbook.ToList() - which returns a List<Book> - to a List<T> which is the declared type of newlist.

I think your ultimate solution is to define your query class as NOT generic. It doesn't seem to be important to the functionality of your class as you have it written here especially since you are inheriting the Books class which explicitly uses the Book class. Is there some reason why this would not work?
Expand|Select|Wrap|Line Numbers
  1. class query : Books
  2. {
  3.     public List<Book> execute()
  4.     {
  5.         //you don't need the newlist variable either, btw
  6.         return listbook.ToList();
  7.     }
  8. }
  9.  
Jan 22 '12 #2
An individual must be aware that, these could be situations sleeplessness won?t disappear completely untreated - Be proactive learn relaxation techniques and learn what natural herbs and supplements will assist and eliminate what "I can't sleep" from the vocabulary and find a cure for insomnia once and just about all If you experience a big loss, while within the mourning period, sleep may be difficult Stress is inevitable in many individuals's lives as many working adults work more hours now, than they had previously This frequently becomes so unbearable that you simply aren't even in a position to eat simple . sweet treat or drink simple . hot or cold beverage You can even find caffeine in chocolate, especially chocolate brown, and in certain nuts, and after all in several soda pops I had a worker named Mary who I was having some minor problems with, and I just couldn't get her name from my head Let go the frustrations and permit your mind to focus on less intense things It is very important being diagnosed sooner instead of later if you are indeed struggling with insomnia or some other related issue Go to bed while you're tired and end up the lights can't sleep through the night

Insomnia Cures with Treatments : I can't sleep at night

Researchers prove that using a burglar alarm clock to wake you up shouldn't be good Toddlers could be worse than babies because they keep themselves awake by distraction and exploring things If it can be, you will want put on the nasal mask to bed nightly About 50% our own daily speech is consists of approximately 100 common words If you're still having difficulty, the next step is to consider some natural sleep remedies What works with regard to you someone might not work for others Have a certain very light meal or drink - why not a glass of warm milk with honey or a small piece of excellent quality, black chocolate These tackle the basis cause of insomnia as well as simpler and long-term solutions Caffeine can stay in your body for between five to eight hours at a time The truth is by using a simple natural male enhancement strategy you'll be able to permanently grow a much bigger stronger plus more attractive penis from and with a tad more confidence as well too!
Feb 5 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Abhi | last post by:
In the following hypothetical example I want to build a generic list of unique string items. How should I implement the pred function so that it returns true/false if target string exists in the...
5
by: majm | last post by:
I'm trying to implement strongly typed lists in the 2.0 framework. I'm using VS2005 beta 2. So far, System.Collections.Generic.List appears to be the ideal solution. However, the...
11
by: ZenRhapsody | last post by:
Has anyone done any performance testing between new generic Lists and single dimensional arrays? I really like the code flexibility the List provides since I don't know how many items I will...
3
by: snesbit | last post by:
I have a structure called SearchAreaListItem. The structure has some properties. The application implements this as a collection.generic.list(of SearchAreaListItem) I load the collection up ...
1
by: Macca | last post by:
Hi, I am considering using a Generic List to hold user defined class entries. Since this List will be accessed by multiple threads I need it to be threadsafe. It appears there is no easy way to...
0
by: crazyone | last post by:
I've got a gaming framework i'm building and i want to save myself the trouble of reading and writting the complete game data to a custom file and load/save it to an XML file but i'm getting...
3
by: Peter Olcott | last post by:
How does not specify the sort criteria for Generic.List ?? The way that this is done in C++ STL is to implement operator<(), how is this done in C# and DotNet for Generic.List ???
3
by: shapper | last post by:
Hello, How can I convert a Generic.List(Of String) to a single string where all elements are separated by a comma? My string would become: "item1,item2,item3" Thanks,
3
by: Arcadefreaque | last post by:
I'm realizing how little I know about C++ today as I try to convert some functionality from VB.Net to C++. I have a procedure that I need to pass a List of objects to, and cannot see how to do...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.