Created
April 22, 2012 15:49
-
-
Save giggio/2464791 to your computer and use it in GitHub Desktop.
Iterating over a dynamic list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
namespace DynamicForeach | |
{ | |
[TestClass] | |
public class ForeachTest | |
{ | |
[TestMethod] | |
public void ForeachDynamicTest() | |
{ | |
var a = new {A = 1}; | |
var b = new {A = 1}; | |
var c = new {A = 1, B = 2}; | |
var array = new ArrayList {a, b, c}; | |
var total = 0; | |
foreach (dynamic item in array) | |
{ | |
total += item.A; | |
} | |
Assert.AreEqual(3, total); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment