Call a static method of a custom class
The original code contains a few typos (e.g. Class
, sting
) and a mistake - the class has to be public
.
Here is the corrected code which works without errors:
# the corrected code added inline (might be in a DLL, as well):Add-Type @'public class Student{ public static string GetData(string id) { return "data1"; } public static string GetData(string fName, string lName) { return "data2"; }}'@# call the static method:[Student]::GetData('myId')
Make sure that your dll containing the Student class is not compiled with "Any CPU" option in Visual Studio, try compiling it for x86.