Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<object> objs = new List<object>
- {
- new Object(),
- new Object(),
- new Object(),
- new Object()
- };
- foreach (object o in objs)
- {
- if (o == objs.First())
- {
- System.Diagnostics.Debug.WriteLine("First object - do something special");
- }
- else
- {
- System.Diagnostics.Debug.WriteLine("object Do something else");
- }
- }
- List<int> ints = new List<int> { 0, 0, 0, 0 };
- foreach (int i in ints)
- {
- if (i == ints.First())
- {
- System.Diagnostics.Debug.WriteLine("First int - do something special");
- }
- else
- {
- System.Diagnostics.Debug.WriteLine("int Do something else");
- }
- }
- List<int> ints = new List<int> { 0, 0, 0, 0 };
- foreach (int i in ints)
- {
- if (i == ints.First())
- {
- System.Diagnostics.Debug.WriteLine("First int - do something special");
- }
- else
- {
- System.Diagnostics.Debug.WriteLine("int Do something else");
- }
- }
- boolean
- using(var iter = ints.GetEnumerator()) {
- if(iter.MoveNext()) {
- // do "first" with iter.Current
- while(iter.MoveNext()) {
- // do something with the rest of the data with iter.Current
- }
- }
- }
- if(ints.Any()) {
- var first = ints.First();
- // do something with first
- }
- foreach(var item in ints.Skip(1)) {
- // do something with the rest of them
- }
- using System;
- using System.Collections.Generic;
- using MiscUtil.Collections;
- class Example
- {
- static void Main(string[] args)
- {
- List<string> list = new List<string>();
- list.Add("a");
- list.Add("b");
- list.Add("c");
- list.Add("d");
- list.Add("e");
- foreach (SmartEnumerable<string>.Entry entry in
- new SmartEnumerable<string>(list))
- {
- Console.WriteLine ("{0,-7} {1} ({2}) {3}",
- entry.IsLast ? "Last ->" : "",
- entry.Value,
- entry.Index,
- entry.IsFirst ? "<- First" : "");
- }
- }
- }
- foreach(int i in ints.Take(1))
- {
- //do first thing
- }
- foreach(int i in ints.Skip(1))
- {
- //do other things
- }
- var list = new List<Int32>();
- // do something with list.First();
- foreach (var item in list.Skip(1))
- {
- // do other stuff
- }
- List<int> ints = new List<int> { 0, 0, 0, 0 };
- System.Diagnostics.Debug.WriteLine("First int - do something special" + ints.FirstOrDefault().ToString());
- foreach (int i in ints.Skip(1))
- {
- {
- System.Diagnostics.Debug.WriteLine("int Do something else");
- }
- }
Add Comment
Please, Sign In to add comment