0

I'm trying to convert this fragment of code from C# into VB.Net:

var objects = new List<dynamic>();

foreach (DataRow row in dt.Rows)
{
    dynamic obj = new ExpandoObject();

    foreach (DataColumn column in dt.Columns)
    {
        var x = (IDictionary<string, object>)obj;
        x.Add(column.ColumnName, row[column.ColumnName]);
    }
    objects.Add(obj);
}

The problem I'm running into is trying to figure out how to create a List<dynamic> in VB.Net. Can someone please provide some guidance on how this works in VB.Net?

Icemanind
  • 47,519
  • 50
  • 171
  • 296
  • 1
    Have you tried using a `List(Of Object)`? See [here](http://stackoverflow.com/q/2889974/2330053) for more info... – Idle_Mind Jun 05 '15 at 20:42
  • @Idle_Mind - No I haven't. `Object` just "feels" wrong. Like its being statically checked by the compiler instead of dynamically at run time. I will give it a shot though and see what happens. – Icemanind Jun 05 '15 at 20:48
  • According to an answer in [this post](http://stackoverflow.com/questions/2889974/vb-net-equivalent-for-c-sharp-dynamic-with-option-strict-on), the closest thing to `dynamic` would be `object`, with `option strict off`. – Rein S Jun 05 '15 at 21:09
  • @Idle_Mind - It does appear to be working with `Object`. I'm still testing though. Thank you – Icemanind Jun 05 '15 at 21:14
  • @ReinS - Yeah I saw that post. Using `Object` just felt wrong though. Like the compiler would flag me or something. But it does appear to work so far. Still testing though. – Icemanind Jun 05 '15 at 21:15
  • Don't try to write VB code that is 100% correspondent to that C# code. The `dynamic` keyword is used to implement late-binding in C#. Obviously late-binding works quite differently in VB. – jmcilhinney Jun 06 '15 at 07:08
  • I think this link [MSDN Early and Late Binding (Visual Basic)](https://msdn.microsoft.com/en-us/library/0tcf61s1.aspx) is quit clear. And this too [VB.Net equivalent for C# 'dynamic' with Option Strict On](http://stackoverflow.com/a/2890023/1565525) – Fabio Jun 06 '15 at 15:59

0 Answers0