array manipulations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?cm9kY2hhcg==?=

    array manipulations

    hey all,
    Label[] lbls = {Label1, Label2, Label3};

    i know you can iterate thru the elements, cast to Label object, and then set
    its visibility. But is there a way to set the elements all at once without
    loop structures?
    just wondering.

    thanks,
    rodchar
  • Peter Duniho

    #2
    Re: array manipulations

    On Fri, 22 Feb 2008 19:53:01 -0800, rodchar
    <rodchar@discus sions.microsoft .comwrote:
    hey all,
    Label[] lbls = {Label1, Label2, Label3};
    >
    i know you can iterate thru the elements, cast to Label object, and then
    set
    its visibility.
    Just to be clear: if you have an array declared as Label[], there is no
    need to cast any element to a Label. Retrieving an element from the array
    gives you something that's already a Label type.
    But is there a way to set the elements all at once without
    loop structures?
    Do you mean "set the visibility of each element"? That is, set
    Label.Visible to "true" for each element? Or otherwise perform some
    specific operation on each element?

    If so, then no. Somewhere, something needs to loop on the elements.

    However, there are of course ways to write code such that this looping is
    done implicitly. For example, you could use the Array.ForEach() method,
    which takes as a parameter a method to call for each element. You can
    provide a method that sets the Visible property, and the ForEach() method
    will call that other method repeatedly, once for each element in the array.

    Pete

    Comment

    • =?Utf-8?B?cm9kY2hhcg==?=

      #3
      Re: array manipulations

      thank you for the insight pete,
      rod.

      "Peter Duniho" wrote:
      On Fri, 22 Feb 2008 19:53:01 -0800, rodchar
      <rodchar@discus sions.microsoft .comwrote:
      >
      hey all,
      Label[] lbls = {Label1, Label2, Label3};

      i know you can iterate thru the elements, cast to Label object, and then
      set
      its visibility.
      >
      Just to be clear: if you have an array declared as Label[], there is no
      need to cast any element to a Label. Retrieving an element from the array
      gives you something that's already a Label type.
      >
      But is there a way to set the elements all at once without
      loop structures?
      >
      Do you mean "set the visibility of each element"? That is, set
      Label.Visible to "true" for each element? Or otherwise perform some
      specific operation on each element?
      >
      If so, then no. Somewhere, something needs to loop on the elements.
      >
      However, there are of course ways to write code such that this looping is
      done implicitly. For example, you could use the Array.ForEach() method,
      which takes as a parameter a method to call for each element. You can
      provide a method that sets the Visible property, and the ForEach() method
      will call that other method repeatedly, once for each element in the array.
      >
      Pete
      >

      Comment

      Working...