logo
down
shadow

C# List IList or IEnumerable as argument


C# List IList or IEnumerable as argument

By : Madelaine Castillo
Date : January 12 2021, 08:33 AM
I hope this helps . Here is the article that made me change my mind about all that and made me start following the principle of
code :


Share : facebook icon twitter icon
Cannot add items to an IList/List being casted from an IEnumerable

Cannot add items to an IList/List being casted from an IEnumerable


By : user2976565
Date : March 29 2020, 07:55 AM
it should still fix some issue In comments on one of the answers above you say "I'm trying to avoid copying the list."
You are trying to add data to an object whose underlying type is IEnumerable. But an IEnumerable object is not an actual container, it's an interface. You can't add stuff to an interface. But you can assign another object that implements that interface to it.
code :
obj2.Stuff = Enumerable.Range(0, 5000).Select(i => "Iteration " + i.ToString());
XmlSerializer - IEnumerable or IList as LIst

XmlSerializer - IEnumerable or IList as LIst


By : merbng
Date : March 29 2020, 07:55 AM
it fixes the issue Since you can't change the class, create a new class, inheriting from the class you want to serialize and from IXmlSerializable. In addition, you can override the base Colors array with the new keyword.
Try this one:
code :
public class Something
{
    public int Id { get; set; }

    public string Text { get; set; }

    public IEnumerable<string> Colors { get; set; }
}

public class MySerializableSomething : Something, IXmlSerializable
{
    public new List<string> Colors { get; set; }

    public MySerializableSomething()
    {
        Colors = new List<string>();
    }

    public XmlSchema GetSchema()
    {
        return null;
    }

    public void ReadXml(XmlReader reader)
    {
        while (reader.Read())
        {
            switch (reader.LocalName)
            {
                case "Id": Id = reader.ReadElementContentAsInt(); break;
                case "Text": Text = reader.ReadElementContentAsString(); break;
                case "Color": Colors.Add(reader.ReadElementContentAsString()); break;
            }
        }
    }

    public void WriteXml(XmlWriter writer)
    {
        writer.WriteElementString("Id", Id.ToString());
        writer.WriteElementString("Text", Text);

        writer.WriteStartElement("Colors");

        foreach (var color in Colors)
        {
            writer.WriteElementString("Color", color);
        }

        writer.WriteEndElement();
    }
}
Comparison between List, IList, and IEnumerable

Comparison between List, IList, and IEnumerable


By : Anthony Ecuman
Date : March 29 2020, 07:55 AM
hop of those help?
IEnumerable is the base interface that the following extend or implement. It doesn't allow for direct access and is readonly. So use this only if you intend to iterate over the collection.
ASP.NET MVC cannot convert IList to IEnumerable? Also tried with IList to IList and still an error

ASP.NET MVC cannot convert IList to IEnumerable? Also tried with IList to IList and still an error


By : Stepan Shykerynets
Date : March 29 2020, 07:55 AM
may help you . Just for fun here is a rewrite i think will do the trick for you, as well as its a little simpler.
code :
public IList<Courses> GetHallamUniCourses()
{
    return _hallamUniProxy.GetAllCourses().Select(a=> 
           new Courses()
           {
               CourseID = a.CourseId,
               CourseName = a.CourseName,
               CourseDescription = a.CourseDescription,
               EntryRequirements = a.EntryCriteria
           }).ToList();
}
//The name of the class must be Name+Controller, and it must extend Controller
class SomeController: Controller{
    //This is a method in the controller, it returns a Result
    //its URI is http[s]://Domain/Some
    public ContentResult Index(){
        return Content("Hello");
    }

    //This is a sub method of controller some, it's URI is http[s]://Domain/Some/Else
    public ContentResult Else(){
        return Content("Hello");
    }
}
C# IEnumerable, ICollection, IList or List?

C# IEnumerable, ICollection, IList or List?


By : Rajath
Date : March 29 2020, 07:55 AM
should help you out It's kinda hard to answer this because it's very easy to post an opinion, and not an answer. I'll try though.
This is a fundamental question about responsibility, more specifically, good API design.
Related Posts Related Posts :
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org