Create IList with one element - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Create IList with one element

Demo Code


using System.Collections;
using System;/*from ww w.  j a v a  2 s .c om*/

public class Main{
    public static IList singleton(object o)
      {
         ArrayList list = new ArrayList();
         list.Add(o);
         return list;
      }
    public static bool add(ICollection list, object value)
      {
         if (!((IList) list).Contains(value))
         {
            ((IList) list).Add(value);
            return true;
         }
         else
            return false;
      }
}

Related Tutorials