.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

array of objects

Posted By:      Posted Date: September 13, 2010    Points: 0   Category :ASP.Net
Hi , i want to store objects in a array, that is array of objects    

View Complete Post

More Related Resource Links

Class which contains an array of objects of type "Class2"



1  Partial Class _Default
2  Inherits System.Web.UI.Page

3 Public Function Ohjoy(ByVal X As Integer) As Integer
4 Dim theClass As New Class1 '= New Class1()
5    theClass.ReSize(0)
6    theClass.myBaby(0).GetName(0) = "Hello" 'Property Chars is read only'
7    Return 1
8 End Function
I have a first class named "Class1". I have a second class named "Class2" Class2, is a member of class 1,
and is implemented as an array of objects of type Class 2.

If I try and call the Accessor GetName() my hard coded value "Hello" in my accessor is not returned? Only
an alpha character like "T"

Also if I try and assigne a value using the setter GetName() it does not work, and the compiler gives me
an error message "property Chars is ReadOnly? Does anyone know what is wrong in my code? Line 6 above


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class

Public Class Class1
    Dim bs As Integer
    Public myBaby() As Class2
    Public myB As Class2
    Public Function ReSize(By

How to make an array of class objects in Visual Basic

How can I make an array of objects in VB.net. Here is the requirement.Basically I have a class named hotel. I need to dynamically add customersto the hotel class using the Customer class. So basically if in the Hotelclass I can have an array of Customer objects that would be great. How can I do this in VB .net ? Public Class Hotel  ' I need an array of Customer objects. objCustomers End Class   Public Class Customer Private custId As Integer Private custName As String Private custAddress As String Private custCity As StringEnd Class Pseudo code:  Dim Hilton As Hotel = new Hotel()   Hilton.objCustomers(5) ' Declare an array of 5 customer objects   Hilton.objCustomers(0).CustId=1  Hilton.objCustomers(0).CustName="JoJo Smith"  Hilton.objCustomers(0).custAddress="122 Emory Lane"  Hilton.custCity="Merry More"  .  .  .  Hilton.objCustomers(4).CustId=1  Hilton.objCustomers(4).CustName="Ice Baby"  Hilton.objCustomers(4).custAddress="66 Domino Drive"  Hilton.custCity="Miami"    End While

How to create an array of VB.net objects from a VB .net class


I need to create an array of a class type. Populate the values in the class and then pass
the array to a subroutine. I havent figured out how to do this properly as I get a null
reference exception. Can someone show me how to create/instantiate the array of objects?
Here is a simple example with only one property named "_momentum". My actuall class has about
10 properties/variables in actuality

Public Class Torsion

 Dim _momentum As integer

 Public Property Momentum
            Return _momentum
    End Get
    Set(ByVal As Integer)
      _momentum = value
End Propterty

' Later in the code I try to create and object of the class

Dim x(0) As Torsion

Passing an array of objects back from a webservice

I can pass an object back from the webservice (e.g. a Person object).

I want to be able to pass back mutiple Person objects back from the webservice.

It does not look like you can pass a collection across from a webservice (if it is possible, please educate me on how).

Is it possible to pass back an array of objects? How would you do this?


lee franke

[RESOLVED] Cannot deserialize an array of objects (of variable type)


Hi helpful folks and gurus

I have been developing an application which uses a derived class inherited from TreeView, with the aim of putting custom objects on the nodes.  The method I have been using is to have a variable array against the node (of type object) which contains variables in custom classes to contain each of the variables associated with the node.

The two problems I had to overcome were, how to serialize a TreeView, and how to serialize an array of objects (of variable type).  Good thing is I overcame both of these with some work of some other folks (and 3 days of my own work).

TreeView: http://www.codeproject.com/KB/vb/TreeViewDataAccess.aspx?display=Print

Object Array (NOT of variable type). adapted to variable type: http://www.codeproject.com/KB/XML/xmlserializerforunknown.aspx

Serialization works a charm..  Deserialization naddah..  Can find no sufficent documentation for me to debug and work on manual deserialization (of only one variable, the variable array of objects).  All others are handled by the regular deserializer.

Effectively the xmlserializerforunknown URL provided a solution which manually handles both the type handling and the handling of the object array.

The main error I'm having lies in the ReadXml, function.  I just can't align the xml with the code.


Binding an array to dropdown list


I have the following string which is a list of urls. How do I get this to work so the url shows for the selection and also is the value?      


allLinks = newAllLinks
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks


 ArgumentNullException: Value cannot be null.
Parameter name: container]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +121
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8

Need help with objects and arrays


I have an objuct that I declared like this:

    Class DailyStats
        Dim _day As String
        Dim _hour As String
        Dim _impressions As String
        Dim _clicks As String
        Property Day() As String
                Return _day
            End Get
            Set(ByVal value As String)
                _day = value
            End Set
        End Property
        Property Hour() As String
                Return _hour

how to get an array of all the asp.net textbox control inside create user wizard control?



How can I get all the textboxes inside a create user wizard control using getElementsByTagName().

Below is my JQuery code:

<script type="text/javascript">
        function addLoadEvent(func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            } else {
                window.onload = function() {

        function prepareInputsForHints() {
            var inputs = document.getElementsByTagName("asp:TextBox");
            for (var i = 0; i < inputs.length; i++) {
                inputs[i].onfocus = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
                inputs[i].onblur = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "none";



<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

How to check for null/empty strings on dynamic objects?


What is the proper way to check for null or empty strings on dynamic objects? This is the only solution I've found so far:

if (admin.PasswordHash.GetType() == typeof(DBNull) || admin.PasswordHash == string.Empty)

If the field is null, the object returned is DBNull.Value, but if the field is empty string, it's return as a System.String object. This makes it impossible to do regular "admin.PasswordHash == DBNull.Value" check, as that will fail whenever the field has been set to empty string. Is my example the right (and only) way to go?

How to cast integer values as an array of enum values?


Hello all!

I'm working with VS2010 Beta2, ASP.NET and Dynamic Data. I'm using VB but will certainly be happy to receive a C# example if necessary. Laughing

I used a few of Steve's examples (Writing Attributes and Extension Methods for Dynamic Data and Dynamic Data - Hiding Columns in selected PageTemplates) to create a custom property attribute to be applied to a dynamic data column and want it to accept an array of enum values (each value will represent a dynamic data page template where this column should not be displayed).  My new attribute works fine when I hardcode it like this, meaning the HideColumnIn attribute is properly populated with the array of enum values:

<HideColumnIn(PageTemplate.List, PageTemplate.Edit)> _
Public Property My_DD_Column As Object


However, I want to store the values to be used for the HideColumnIn in the DB as integer values that correspond to the

how to serialize objects ??


Is there any way or process to serialize the the objects?? i am trying to store the instance of few control in viewstate but it shows error msg that it is not a serialized object. should i perform some steps to serialize the objects ???

Unity - Inject array



I have the following in the config file...

container.RegisterType<ProductInstanceValidatorBase, CartItemStockValidator>();
container.RegisterType<ProductInstanceValidatorBase, MonthlyCartItemValidator>();

..constructor like so...

 public CartValidator(ProductInstanceValidatorBase[] validators)
   this.validators = validators;

...I call the following but the array is empty...


Any ideas?

Cheers, WT.



Converting ReportDocument object into byte array ?


Hi All,

          Is it possible to convert the Report Document object as a byte array and store it in SQL , later retrieve and assing it to a report ?


Invalid length for a Base-64 char array for my coding in ASP.net C#. How to solve it ?


Hi Friends ,

I have done encrypted password and decode but i got error  like  this  " Invalid length for a Base-64 char array" .

Pls help . Thanks


psswd = txtPassword.Text;

pwed = base64Decode(psswd);

public string base64Decode(string sData)
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder utf8Decode = encoder.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(sData);
            int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            string result = new String(decoded_char); return result;

Query an arraylist of array list using linq


I have an array list called Customer. I t holds a list of array list which has the account details.

proj.customer -> collection of arraylist of type customer

proj.customer.account -> collection of arraylist of type account

Account array list holds type account and it has a poperty account balance. How can I query all accounts which has account balance  >100

I tried the following one

var Accountlist= from Account accountdetails in proj.customer.account

where accountid.balance >100

select accountdetails.id

But it is always throwing an error saying cannot cast type customer to type account

Please help

Cutting Edge: Expando Objects in C# 4


The .NET Framework 4 introduces some new features that enable you to go beyond static types. We explore dynamically expando objects and demonstrate how they can be used like dynamically updatable dictionary objects.

Dino Esposito

MSDN Magazine July 2010

Basic Instincts: Collection and Array Initializers In Visual Basic 2010


Collection Initializers are a great addition to the language and allows concise syntax in order to initialize both framework and user defined collection types.

Spotty Bowles

MSDN Magazine October 2009

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend