Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 794879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:23:10+00:00 2026-05-14T22:23:10+00:00

can someone help me pls, im new to vb.net and im trying to work

  • 0

can someone help me pls, im new to vb.net and im trying to work through the nhibernate firstsolution sample (written in c# re-posted here https://web.archive.org/web/20090831053827/http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx as thier site is down again) and im struggling to convert this one bit. ive tried numerous convertors; telerik, developerfusion and a several others but none of the code produced will compile and i cant see the why…

if you search for this method youll find where im upto…

private readonly Product[] _products = new[] 
{
    new Product {Name = "Melon", Category = "Fruits"},
    new Product {Name = "Pear", Category = "Fruits"},
    new Product {Name = "Milk", Category = "Beverages"},
    new Product {Name = "Coca Cola", Category = "Beverages"},
    new Product {Name = "Pepsi Cola", Category = "Beverages"},                 
};

' just the next part of the tutorial, ive resolved the "var" in vb.net 2005 bit np
private void CreateInitialData()        
{
    using(ISession session = _sessionFactory.OpenSession())                
        using(ITransaction transaction = session.BeginTransaction())                  
        {
           foreach (var product in _products)
               session.Save(product);
               transaction.Commit();
        }
}

since my c# and vb are both shakey at best ive tried to use several conversion utils/sites.

developer fusion gives:

Private ReadOnly _products As Product() = New () {New Product(), New Product(), New Product(), New Product(), New Product()}

telerik gives

Private ReadOnly _products As Product() = New () {New Product() With { _
 .Name = "Melon", _
 .Category = "Fruits" _
}, New Product() With { _
 .Name = "Pear", _
 .Category = "Fruits" _
}, New Product() With { _
 .Name = "Milk", _
 .Category = "Beverages" _
}, Nw Product() With { _
 .Name = "Coca Cola", _
 .Category = "Beverages" _
}, New Product() With { _
 .Name = "Pepsi Cola", _
 .Category = "Beverages" _
}}

which seems the most useful except it complains about a type expected here “New () {…”
ive tried various things including the missing type in the New() as suggested in the comments but just cant figure it out… what am i missing? am i just being dumb? or isnt there and equivilent?

This is all the code i have, as it is a simple copy n paste from the tutorial c# to the convertor sites. in the mean time ive used the developer fusion definition and manually populated the array elements in aother method. i.e.

Private _products As Product() = {New Product(), New Product(), New Product(), New Product(), New Product()}
Private Sub CreateInitialData()
    ' =================
    ' since i couldnt figure out how to convert the initialisation of the 
    ' "_products" array/collections whatever it is, i cheated and did this, 
    ' seems to work ok though probably poor practice
    With _products(0)
        .Name = "Melon"
        .Category = "Fruits"
    End With
    ' etc....
End Sub

background if it matters: vs2005, .net 2.0

Cheers all

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:23:11+00:00Added an answer on May 14, 2026 at 10:23 pm

    VB.NET 8.0/Visual Studio 2005 does not support use of the With statement for direct object initialization. However, I believe you should be able to encapsulate the initialization in a Function:

        Private ReadOnly _products() As Product = BuildProducts()
    
        Private Function BuildProducts() As Product()
            Dim products(4) As Product
    
            Dim product0 As New Product
            With product0
                .Name = "Melon"
                .Category = "Fruits"
            End With
    
            Dim product1 As New Product
            With product1
                .Name = "Pear"
                .Category = "Fruits"
            End With
    
            Dim product2 As New Product
            With product2
                .Name = "Milk"
                .Category = "Beverages"
            End With
    
            Dim product3 As New Product
            With product3
                .Name = "Coca Cola"
                .Category = "Beverages"
            End With
    
            Dim product4 As New Product
            With product4
                .Name = "Pepsi Cola"
                .Category = "Beverages"
            End With
    
            products(0) = product0
            products(1) = product1
            products(2) = product2
            products(3) = product3
            products(4) = product4
    
            Return products
        End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone help me with this query. I have this table for sample: FILE
Can someone help me pls. I am ready to deploy my web application. I
Can someone help me? I am trying to do something like the following: #include
Can someone help me out with something. I'm trying to get the current part
Can someone help me with some coding. I want to work out what the
Can someone help me achieve multiple zend pagination in a view using ajax. I
Can someone help by showing me how to sort a LINQ expression. I have
Can someone help me understand how to write this case statement properly its not
Can someone help me with creating functions for the following processes? I want to
Can someone help me find the error when I tried to display the list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.