Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT</strong> <em>(2)</em><br> As pointed out in comments, <a href="http://msdn.microsoft.com/en-us/library/dd293617.aspx" rel="noreferrer">VB.NET collection initializers</a> have now been introduced, and a lot of the following post should be considered obsolete.</p> <p><strong>EDIT</strong><br> <a href="http://www.developerfusion.com/tools/convert/csharp-to-vb/" rel="noreferrer">Don't always blindly trust the C# to VB.NET converter</a><br> <s><a href="http://www.developerfusion.com/tools/convert/csharp-to-vb/" rel="noreferrer">Here's a handy tool for online conversion</a></s></p> <p>Turns out <a href="http://www.cynotwhynot.com/blog/post/Does-VBNET-have-Collection-Initializers.aspx" rel="noreferrer">VB.NET doesn't have collection initializers</a>. Which means there is no equivalence of </p> <pre><code>var myList = new List&lt;string&gt;() { "abc", "def" }; </code></pre> <p>... but it <em>does</em> have object initializers. So you can create an instance of a class and assign values to its properties all in one go, but you cannot create an instance of a list and add items to it all in one go.</p> <p>There closest you can get is in the link above. You can create an <em>Array</em> and add items to it in a single operation, and then you have to <code>ToList</code> that array.</p> <p>So this time I've actually compiled the code myself, and it works. Sorry for the hassle</p> <pre><code> Dim EmployeesTemp As Employee() = { _ New Employee() With { _ .firstname = "Aamir", _ .lastname = "Hasan", _ .age = 20 _ }, _ New Employee() With { _ .firstname = "awais", _ .lastname = "Hasan", _ .age = 50 _ }, _ New Employee() With { _ .firstname = "Bill", _ .lastname = "Hasan", _ .age = 70 _ }, _ New Employee() With { _ .firstname = "sobia", _ .lastname = "khan", _ .age = 80 _ } _ } Dim Employees as List(Of Employee) = EmployeesTemp.ToList() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload