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 6049141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:32:31+00:00 2026-05-23T07:32:31+00:00

I have an object called Reservations . Inside Reservations , there is a another

  • 0

I have an object called Reservations. Inside Reservations, there is a another object called Reservation that is an array.

When I do something like the following:

reservations.Reservation[i] = new Reservation(); //reservations if of type Reservations

I get the following error:

Cannot find the method on the object instance

A couple things I noticed is that when I get to this point, it throws an IndexOutOfRangeError and if I hover over the reservations variable, it shows a number.

VB Code

Public Class Reservations
{
    Private RerservationField() as Reservation

    Public Property Reservation() as Reservation()
        Get
            Return Me.ReservationField
        End Get
        Set
            Me.ReservationId = value
        End Set
    End Property
}

Dim reservations As New Reservations()
ReDim reservations.Reservation(0)

Dim i as Integer = 0

reservations.Reservation(i) = New Reservation()

C# Code

public class Reservations
{
    Reservation[] reservation {get;set;}
}

Reservations reservations = new Reservations();
reservations.Reservation = new Reservation[0];
int i = 0;

The VB Code and C# Code, it is instantiating the length of the array based on an xml request. So in the vb code, it was doing this:

 ReDim reservations.Reservation(rq.Reservations.Reservation.Length - 1)

and in the c# code, it was doing this:

reservations.Reservation(rq.Reservations.Reservation.Length - 1).

Is the above my problem. I need to do:

reservations.Reservation(rq.Reservations.Reservation.Length)

rq is the request.

  • 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-23T07:32:31+00:00Added an answer on May 23, 2026 at 7:32 am

    Your line:

    reservations.Reservation = new Reservation[0];
    

    Will create an array of max length 0? Which will basically be non null, but empty..

    You need to instantiate the reservations.Reservation array (SIZE would be how large you want it). You do not** need to -1 from your length. If you specify new Array[1] it will be able to hold 1 element, 2 2 elements, etc.

    Reservations reservations = new Reservations();
    size = rq.Reservations.Reservation.Length
    reservations.Reservation = new Reservation[size ];
    reservations.Reservation[0] = new Reservation();
    

    You could do it in the constructor if you want:

    public class Reservations
    {
      Reservation[] reservation {get;set;}
      public Reservations(int size){
        reservation  = new Reservation[size];
      }
    }
    

    Then the middle step would no longer be needed i.e.:

    Reservations reservations = new Reservations(rq.Reservations.Reservation);
    reservations.Reservation[0] = new Reservation();
    

    Note you should look into using a more advanced collection List

    public class Reservations
    {
      List<Reservation> reservation {get;set;}
      public Reservations(){
        reservation  = new List<Reservation>();
      }
    }
    

    And if you need it as an array you can just do

     reservation.Reservations.ToArray();
    

    and to insert it would be

     reservation.Reservations.Add(theReservation);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would something like this be possible: I have an object called Player: class
I have an object called SampleObject that holds an array of strings called StringArray.
I have an object called Person that has the following properties: int id; Name
I have an object called ValueBox that I created like this: function ValueBox(params) {
I have an object that has properties of another object and one called DataValue
Here is the scenario: I have an object called a Transaction that needs to
I have a UITableView that displays various nsstrings from a custom object called a
Hey. I have an object that has a string property called BackgroundColor. This string
I have a data object -- a custom class called Notification -- that exposes
Why does the DOM have an object called self and another called window when

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.