Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Array List

Array List

Scheduled Pinned Locked Moved C#
data-structurestutorial
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NET India
    wrote on last edited by
    #1

    Hello Everyone, ArrayList arr = new ArrayList(); arr.Add("Manoj"); arr.Add(4); arr.Add(4.5); Arraylist is hetergenous so i've taken three datatype values as shown above But anybody let me know how to print these object's values........

    N H J M 4 Replies Last reply
    0
    • N NET India

      Hello Everyone, ArrayList arr = new ArrayList(); arr.Add("Manoj"); arr.Add(4); arr.Add(4.5); Arraylist is hetergenous so i've taken three datatype values as shown above But anybody let me know how to print these object's values........

      N Offline
      N Offline
      N a r e s h P a t e l
      wrote on last edited by
      #2

      Hi, There is no problem for printing your ArrayyList values by following. ArrayList arr = new ArrayList(); arr.Add("Manoj"); arr.Add(4); arr.Add(4.5); for (int i = 0; i < arr.Count; i++) lblResult.Text += arr[i];

      Naresh Patel

      1 Reply Last reply
      0
      • N NET India

        Hello Everyone, ArrayList arr = new ArrayList(); arr.Add("Manoj"); arr.Add(4); arr.Add(4.5); Arraylist is hetergenous so i've taken three datatype values as shown above But anybody let me know how to print these object's values........

        H Offline
        H Offline
        Hessam Jalali
        wrote on last edited by
        #3

        you can use ToString for primitive types like int ,double,string,... but in some cases ToString does not return the data we expect (like classes we define by our self) so in those cases you can override the ToString() method.

        foreach(object obj in arr)
        Console.WriteLine(obj.ToString());

        hope the post would be useful

        1 Reply Last reply
        0
        • N NET India

          Hello Everyone, ArrayList arr = new ArrayList(); arr.Add("Manoj"); arr.Add(4); arr.Add(4.5); Arraylist is hetergenous so i've taken three datatype values as shown above But anybody let me know how to print these object's values........

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          In addition to the ToString() method suggested above, you can also use GetType() on any object which returns an object of type Type. This object has all the information you could ever need on what types are inside your arraylist.

          --- How to get answers to your questions[^]

          1 Reply Last reply
          0
          • N NET India

            Hello Everyone, ArrayList arr = new ArrayList(); arr.Add("Manoj"); arr.Add(4); arr.Add(4.5); Arraylist is hetergenous so i've taken three datatype values as shown above But anybody let me know how to print these object's values........

            M Offline
            M Offline
            mangrovecm
            wrote on last edited by
            #5

            I think you should use an object then add it to your arraylist. such as You can create an object: myObject obj =new myObject(); obj.Title="Manoj"; obj.Age=4; obj.Weight=4.5; //Add to arraylist ArrayList arr = new ArrayList(); arr.Add(obj); //Get from arraylist for(int i = 0; i < arr.Count; i++) { myObject obj = arr[i] as myObject; Console.Write(obj.Title); .... } Hope that help you vtkiet05

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups