why use IList or List?
<p>I know there has been alot of posts on this but it still confuses me why should you pass in an interface like IList and return an interface like IList back instead of the concrete list.</p>

<p>I read alot of posts saying how this makes it easier to change the implementation later on but I just don't fully see how that works.</p>

<p>Say if I have this method</p>

<pre><code>  public class SomeClass
    {
        public bool IsChecked { get; set; }
    }

 public void LogAllChecked(IList&lt;SomeClass&gt; someClasses)
    {
        foreach (var s in someClasses)
        {
            if (s.IsChecked)
            {
                // log 
            }

        }
    }
</code></pre>

<p>I am not sure how in the future by using IList will help me out.</p>

<p>How about if I am already in the method? Should I still be using IList?</p>

<pre><code>public void LogAllChecked(IList&lt;SomeClass&gt; someClasses)
    {
        //why not List&lt;string&gt; myStrings = new List&lt;string&gt;()
        IList&lt;string&gt; myStrings = new List&lt;string&gt;();

        foreach (var s in someClasses)
        {
            if (s.IsChecked)
            {
                myStrings.Add(s.IsChecked.ToString());
            }

        }
    }
</code></pre>

<p>What do I get for using IList now?</p>

<pre><code>public IList&lt;int&gt; onlySomeInts(IList&lt;int&gt; myInts)
    {
        IList&lt;int&gt; store = new List&lt;int&gt;();
        foreach (var i in myInts)
        {
            if (i % 2 == 0)
            {
                store.Add(i);
            }
        }

        return store;
    }
</code></pre>

<p>how about now? Is there some new implementation of a list of int's that I will need to change out?</p>

<p>So basically I need to see some actual code examples of how if I where using IList would have solved some problem over just taking List into everything.</p>

<p>From my reading I think I could have used IEnumberable instead of IList since I am just looping through stuff.</p>

<p><strong>Edit</strong>
So I been playing around with some of my methods on how to do this. I am still not sure about the return type(if I should make it more concrete or an interface)</p>

<pre><code> public class CardFrmVm
    {
        public IList&lt;TravelFeaturesVm&gt; TravelFeaturesVm { get; set; }
        public IList&lt;WarrantyFeaturesVm&gt; WarrantyFeaturesVm { get; set; }

        public CardFrmVm()
        {
            WarrantyFeaturesVm = new List&lt;WarrantyFeaturesVm&gt;();
            TravelFeaturesVm = new List&lt;TravelFeaturesVm&gt;();
        }
}

 public class WarrantyFeaturesVm : AvailableFeatureVm
    {
    }

     public class TravelFeaturesVm : AvailableFeatureVm
    {

    }

      public class AvailableFeatureVm
    {
        public Guid FeatureId { get; set; }
        public bool HasFeature { get; set; }
        public string Name { get; set; }
    }


        private IList&lt;AvailableFeature&gt; FillAvailableFeatures(IEnumerable&lt;AvailableFeatureVm&gt; avaliableFeaturesVm)
        {
            List&lt;AvailableFeature&gt; availableFeatures = new List&lt;AvailableFeature&gt;();
            foreach (var f in avaliableFeaturesVm)
            {
                if (f.HasFeature)
                {
                                                    // nhibernate call to Load&lt;&gt;()
                    AvailableFeature availableFeature = featureService.LoadAvaliableFeatureById(f.FeatureId);
                    availableFeatures.Add(availableFeature);
                }
            }

            return availableFeatures;
        }
</code></pre>

<p>So I am right now returning IList for the simple fact that I will then add this to my domain model what has a property like this</p>

<pre><code>public virtual IList&lt;AvailableFeature&gt; AvailableFeatures { get; set; }
</code></pre>

<p>the above is an IList itself as this is what seems to be the standard to use with nhibernate. Otherwise I might have returned IEnumberable back but not sure. Still can't figure out what the user would 100% need(that's where return a concrete has an advantage over).</p>

<p><strong>Edit 2</strong></p>

<p>I was also thinking what happens if I want to do pass by reference in my method?</p>

<pre><code>private void FillAvailableFeatures(IEnumerable&lt;AvailableFeatureVm&gt; avaliableFeaturesVm, IList&lt;AvailableFeature&gt; toFill)
            {

                foreach (var f in avaliableFeaturesVm)
                {
                    if (f.HasFeature)
                    {
                                                        // nhibernate call to Load&lt;&gt;()
                        AvailableFeature availableFeature = featureService.LoadAvaliableFeatureById(f.FeatureId);
                        toFill.Add(availableFeature);
                    }
                }
            }
</code></pre>

<p>would I run into problems with this? Since could they not pass in an array(that has a fixed size)? Would it be better maybe for a concrete List?</p>
