Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I use C# convertion types?

Posted on 2011-09-21
5
Medium Priority
?
366 Views
Last Modified: 2013-12-17
Hi,

I have the below collection...

[CollectionDataContract]
    public class ImageLinkCollection : List<ImageLinkItem>
    {
        public void Add(SPBrandImageLink spImageLinks)
        {
            string strUrl = spImageLinks.URL.IndexOf(',') > 0 ? spImageLinks.URL.Split(',')[0].Trim() : "";

            ImageLinkItem i = new ImageLinkItem(Converters.ConvertNullableInt(spImageLinks.Id), spImageLinks.Title,
                                                spImageLinks.Path,
                                                Converters.ConvertNullableDate(spImageLinks.Created),
                                                Converters.ConvertNullableDate(spImageLinks.Modified));

            SPFieldUrlValue spLogo = spImageLinks.Logo as SPFieldUrlValue;
            if (spLogo != null)
                i.Logo = new ImageDownload(i.Id, spLogo.Description, spLogo.Url, i.Created, i.Modified);
            i.Url = strUrl;
            i.Order = (int)Converters.ConvertNullableDouble(spImageLinks.Order);

            Add(i);
        }
    }

I am attempting to add to the collection with the below but I receive the error "Cannot implicitly convert type System.Collections.Generic.List<SPBrandImageLink> to SPBrandImageLink"?...

var query = from SPBrandImageLink in DAL.BrandOnTheInternet.Cast<SPBrandImageLink>()
                            orderby SPBrandImageLink.Order
                            select SPBrandImageLink;

                SPBrandImageLink spImageLinks = query.ToList<SPBrandImageLink>();

                Logger.LogInfo("Found " + query.Count().ToString() + " On The Internet Links for " + HttpContext.Current.User.Identity.Name);

                result.Add(spImageLinks);
0
Comment
Question by:aspnet-scotland
5 Comments
 
LVL 10

Assisted Solution

by:oxyoo
oxyoo earned 1200 total points
ID: 36572454
Instead of:  SPBrandImageLink spImageLinks = query.ToList<SPBrandImageLink>();
Try this:


IList<SPBrandImageLink> spImageLinks = query.ToList<SPBrandImageLink>();

Open in new window

0
 

Accepted Solution

by:
aspnet-scotland earned 0 total points
ID: 36572475
I also had to add the below as a method within ImageLinkCollection changing the initial Add method variable to spImageLink...

public void Add(List<SPBrandImageLink> spImageLinks)
        {
            foreach (SPBrandImageLink spImageLink in spImageLinks)
            {
                Add(spImageLink);
            }
        }

Thanks.
0
 
LVL 16

Assisted Solution

by:Easwaran Paramasivam
Easwaran Paramasivam earned 800 total points
ID: 36572525
Use below code:              

 List<SPBrandImageLink> spImageLinks = query.ToList<SPBrandImageLink>();

0
 
LVL 1

Expert Comment

by:RG59
ID: 36572563
You could just use a var (assuming .Net 3.5 or later) and let .Net take care of it...

var spImageLinks = query.ToList<SPBrandImageLink>();
0
 

Author Closing Comment

by:aspnet-scotland
ID: 36597764
Partially solved myself
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question