How to use the passed string?

This is more of a training exercise, but I was hoping it would help.

I want to create a function like this:

function array_to_array ($stuff, $new_type){ $new_stuff = $stuff -as $new_type $new_stuff } 

I have a problem with passing in strings or even a value like [char] for new_type. I think I need to do something like $type = [char] , but I'm trying to keep it as string as possible.

Is there anyway to do this? How to activate a line?

+4
source share
1 answer

You can do:

 [type] $new_type = "string" 

In a function, it will be:

 function array_to_array ($stuff, [type]$new_type){ $new_stuff = $stuff -as $new_type $new_stuff } array_to_array 1 "string" 
+6
source

Source: https://habr.com/ru/post/1501910/


All Articles