Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<string> sl = new List<string>();List<object> ol;ol = sl;
- List<string> sl = new List<string>();List<object> ol;ol = (List<object>)sl;
- List<object> ol = new List<object>();List<string> sl;sl = (List<string>)ol;
- List<string> sl = new List<string>();
- IEnumerable<object> ol;
- ol = sl.Cast<object>();
- List<string> sl = new List<string>();
- // Add strings to sl
- List<object> ol = new List<object>();
- foreach(string s in sl)
- {
- ol.Add((object)s); // The cast is performed implicitly even if omitted
- }
- var sl = new List<string>();
- // Add strings to sl
- var ol = new List<object>(sl.Cast<object>());
- // OR
- var ol = sl.Cast<object>().ToList();
- // OR (note that the cast to object here is required)
- var ol = sl.Select(s => (object)s).ToList();
- List<string> sl = new List<string>();//populate slList<object> ol = new List<object>(sl);
- List<object> ol = new List<object>();ol.AddRange(sl);
- List<string> sl = new List<string>();
- List<object> ol = sl.Cast<object>().ToList();
- object[] a = new string[] {"spam", "eggs"};
- public IList<B> ConvertIList<D, B>(IList<D> list) where D : B
- {
- List<B> newList = new List<B>();
- foreach (D item in list)
- {
- newList.Add(item);
- }
- return newList;
- }
- private List<Leerling> Leerlingen = new List<Leerling>();
- Leerlingen = (List<Leerling>)_DeserialiseerLeerlingen._TeSerialiserenObjecten.Cast<Leerling>();
Add Comment
Please, Sign In to add comment