what does <object>["text"] mean?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rasarx
    New Member
    • Sep 2007
    • 2

    #1

    what does <object>["text"] mean?

    Being new to VB, I'm trying to understand what a construct like ["name"] means and how to use it. I thought anything with brackets is an escaped variable to allow using keywords like boolean, as in [boolean]. But I don't get this construct, especially in conjuction with an object, as in mo["name"] in the example below. Is mo["name"] an array element? What exactly is it and how do you use it?

    Console.WriteLi ne("Computer details retrieved using Windows Management Instrumentation (WMI)");
    ManagementObjec tSearcher query1 = new ManagementObjec tSearcher("SELE CT * FROM Win32_Operating System");
    ManagementObjec tCollection queryCollection 1 = query1.Get();
    foreach (ManagementObje ct mo in queryCollection 1)
    {
    Console.WriteLi ne("Name : " + mo["name"].ToString());
    Console.WriteLi ne("Version : " + mo["version"].ToString());
    }
  • VBPhilly
    New Member
    • Aug 2007
    • 95

    #2
    Originally posted by Rasarx
    Being new to VB, I'm trying to understand what a construct like ["name"] means and how to use it. I thought anything with brackets is an escaped variable to allow using keywords like boolean, as in [boolean]. But I don't get this construct, especially in conjuction with an object, as in mo["name"] in the example below. Is mo["name"] an array element? What exactly is it and how do you use it?

    Console.WriteLi ne("Computer details retrieved using Windows Management Instrumentation (WMI)");
    ManagementObjec tSearcher query1 = new ManagementObjec tSearcher("SELE CT * FROM Win32_Operating System");
    ManagementObjec tCollection queryCollection 1 = query1.Get();
    foreach (ManagementObje ct mo in queryCollection 1)
    {
    Console.WriteLi ne("Name : " + mo["name"].ToString());
    Console.WriteLi ne("Version : " + mo["version"].ToString());
    }
    It looks like an array or collection.
    However, the curly braces tell me this is not VB.
    I would check with the C# folks to be certain. But, I think "mo" is an array/collection and the "name" and "versions" are indexes of the mo object.

    Comment

    • VBPhilly
      New Member
      • Aug 2007
      • 95

      #3
      Originally posted by Rasarx
      Being new to VB, I'm trying to understand what a construct like ["name"] means and how to use it. I thought anything with brackets is an escaped variable to allow using keywords like boolean, as in [boolean]. But I don't get this construct, especially in conjuction with an object, as in mo["name"] in the example below. Is mo["name"] an array element? What exactly is it and how do you use it?

      Console.WriteLi ne("Computer details retrieved using Windows Management Instrumentation (WMI)");
      ManagementObjec tSearcher query1 = new ManagementObjec tSearcher("SELE CT * FROM Win32_Operating System");
      ManagementObjec tCollection queryCollection 1 = query1.Get();
      foreach (ManagementObje ct mo in queryCollection 1)
      {
      Console.WriteLi ne("Name : " + mo["name"].ToString());
      Console.WriteLi ne("Version : " + mo["version"].ToString());
      }
      Ok, I figured I could give some more detail

      mo is an object of type ManagementObjec t which exists in the queryCollection 1 which is of type ManagementObjec tCollection.
      mo is the object, "name" and "version" are properties of ManagementObjec t. I hope I donthave to explain ToString to you :)

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Looks like Java, to me.

        Comment

        • Rasarx
          New Member
          • Sep 2007
          • 2

          #5
          Thank you all. I saw that code chunk on a web site under VB samples and I thought there was something in VB that I couldn't figure out. You are right. It is some other language.

          Comment

          Working...