Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can I do with C# and Powershell? [closed]

I have a decent understanding of C# and a very basic understanding of powershell. I'm using Windows PowerShell CTP 3, which has been really fun. But I want to go beyond writing scripts/functions. Is there any cool stuff to do with C#?

like image 813
Kredns Avatar asked Apr 12 '09 19:04

Kredns


People also ask

What can C be used for?

C is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, and so on. C programming is an excellent language to learn to program for beginners. Our C tutorials will guide you to learn C programming one step at a time.

What can I do after learning C?

C is the root of all programming languages. If you have a good grip on C, then you can go on learning other programming languages like Python, Java, JavaScript. Nowadays, R programming language is also used by many top companies.

Is C useful anymore?

The C programming language doesn't seem to have an expiration date. It's closeness to the hardware, great portability and deterministic usage of resources makes it ideal for low level development for such things as operating system kernels and embedded software.

Can we do anything in C?

You can do almost everything in any of the programming languages. Of course the way of expressing it will vary, as well as the amount of code, clarity of code, ease of further maintenance. Some tasks can be coded with few lines in Prolog and few pages of code in C++, and so on.


1 Answers

At the highest level you have two different options You can from a C# program host PowerShell and execute PowerShell commands via RunSpaces and pipelines.

Or you can from within PowerShell run C# code. This can be done two ways. With a PowerShell snapin, a compiled dll which provides PowerShell cmdlets and navigation providers, or via the new cmdlet Add-Type, which lets you dynamically import C#, VB, F# code. From the help

$source = @" public class BasicTest {     public static int Add(int a, int b)     {         return (a + b);     }      public int Multiply(int a, int b)     {         return (a * b);     } } "@  Add-Type -TypeDefinition $source [BasicTest]::Add(4, 3) $basicTestObject = New-Object BasicTest  $basicTestObject.Multiply(5, 2) 
like image 191
Scott Weinstein Avatar answered Sep 22 '22 03:09

Scott Weinstein