.NET Framework - array manipulations
Asked By rodcha
22-Feb-08 10:53 PM
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
Array
(1)
ForEach
(1)
Rodchar
(1)
Metho
(1)
Lbls
(1)
Peter Duniho replied...
On Fri, 22 Feb 2008 19:53:01 -0800, rodchar =
en =
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 arr=
ay =
gives you something that's already a Label type.
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 i=
s =
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() metho=
d =
will call that other method repeatedly, once for each element in the arr=
ay.
Pete
rodcha replied...
thank you for the insight pete,
rod.

which network i'm on and setup some sort of indicator on the page? thanks, rodchar C# Discussions ManagementObjectSearcher (1) RelatedObjectQuery (1) IPAddress (1) ManagementObject (1) GetHostAddresses (1) NetConnectionID (1) Console (1) Array (1) On Wed, 12 Mar 2008 17:28:00 -0700, rodchar There's no standardized way to do that. But if you know something specific about check an ip address in csharp? On Thu, 13 Mar 2008 05:57:06 -0700, rodchar There are a variety of ways to do it, depending on what information you need because i notice that was different? On Thu, 13 Mar 2008 12:05:00 -0700, rodchar Unless your local host is the default gateway, then yes. . .it would be different, since true, (int)NetConnectionStatus.Connected); SelectQuery selectQuery = new SelectQuery(q); using(ManagementObjectSearcher adapterSearcher = new ManagementObjectSearcher(selectQuery)) { foreach (ManagementObject adapter in adapterSearcher.Get()) { Console.WriteLine("{0}, {1}", adapter["NetConnectionStatus"].ToString(), adapter["NetConnectionID"].ToString RelatedObjectQuery ("associators of {Win32_NetworkAdapter.DeviceId = '" + adapter["DeviceId"]+ "'}"); adapterRelatedQuery.RelatedClass = using(ManagementObjectSearcher adapterConfigSearcher = new ManagementObjectSearcher(adapterRelatedQuery)) { foreach (ManagementObject adapterConfig in adapterConfigSearcher.Get()) { foreach(string ip in adapterConfig["IPAddress"] as Array) Console.WriteLine(" \ tIpAddress: {0}", ip); } } } } } } Willy. thanks for
Trouble Using System.Array.ForEach .NET Framework I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return String.Format("'{0 with single quotes. However, I am having trouble getting this to work using the System.Array.ForEach method. This may be partially because I am not very experienced with Actions or Delegates could tell me what I am doing wrong, I would appreciate it. Thanks. (NOTE: The Array that I want to modify the values of is not one that I have permission
Array.CreateInstance failure .NET Framework Hello, Bellow is a little except that creates a static array dynamically. However it creates a two dimensional one instead of a single dimensional. Why???? public static void Main(string[] args) { int[] intArray = new int[]{2, 3}; Type type = intArray.GetType(); Array array = Array.CreateInstance(type, 0); / / array is a two dimensional array. Why? intArray = (int[]) array; / / Throws InvalidCastException, as expected Console.WriteLine(); } .NET CLR Discussions InvalidCastException (1) Array.CreateInstance (1) Console
array .NET Framework this works great - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - function Get-RandomElement($Array) { $Array[ $Random.Next( $Array.Count ) ] } $test = "1", "2", "3", "4", "5", "6" $Random = New-Object Random $Message = Get-RandomElement 1) BB03B06CE559 (1) Andthus (1) Ratehr (1) Repro (1) your input isn't entering an array , but ratehr just one string, and thus can't be indexed. . If you are sure work fine with comma-separated input with or without quotation marks: function Get-RandomElement($inputstring) { $array = invoke-expression $inputstring $array[$Random.Next($Array.Count)] } -Hecks and if sometime types del *.* instead of "1", "2", "3", "4" you are