combine Process()

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
Can you combine two process() ?

VB.NET:
dim myProcess1 as Process() = Process.GetProcessesByName("abc")
dim myProcess2 as Process() = Process.GetProcessesByName("def")

dim myProcess3 as Process()

myProcess3 = myProcess1 + myProcess2
 
You can, sort of, just not using an array...

        Dim lProcesses As New List(Of Process)

        lProcesses.AddRange(Process.GetProcessesByName("abc"))
        lProcesses.AddRange(Process.GetProcessesByName("def"))
 
You can create a new array and use the Array.Copy method to copy each source array to that, or you can use Linq to concat them for you and the ToArray extension to 'export' as array if you really need it to be an array object:
Dim myProcess3 = myProcess1.Concat(myProcess2).ToArray

You can also do as Herman suggested when you need to dynamically add to a collection, and same use the ToArray extension when and if you need the array object.
 
You can, sort of, just not using an array...

        Dim lProcesses As New List(Of Process)

        lProcesses.AddRange(Process.GetProcessesByName("abc"))
        lProcesses.AddRange(Process.GetProcessesByName("def"))
Oh, I think I may have misinterpreted the question. I thought the question was can you combine two Process objects into a single Process object, not can you combine two Process arrays into a single Process array. In that case then it's easy because an array is an array. It doesn't matter whether it's an array of Strings, Integers or Processes, it is still an array and behaves just like all arrays do. There are various ways to create a single array containing the elements from two other arrays but, assuming .NET 3.5 or later, I would tend to throw a bit of simple LINQ at it:
Dim arr3 = arr1.Concat(arr2).ToArray()
Because of type inference, that same code will work no matter the type of the array elements, as long as they are the same for arr1 and arr2.
 
Back
Top