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.
Your line:
Will create an array of max length 0? Which will basically be non null, but empty..
You need to instantiate the reservations.Reservation array (
SIZEwould 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.You could do it in the constructor if you want:
Then the middle step would no longer be needed i.e.:
Note you should look into using a more advanced collection List
And if you need it as an array you can just do
and to insert it would be