Created
October 16, 2015 00:21
-
-
Save JoshVarty/73073c0b596a192bb7b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ScriptOptions scriptOptions = ScriptOptions.Default; | |
//Add reference to mscorlib | |
var mscorlib = typeof(System.Object).Assembly; | |
var systemCore = typeof(System.Linq.Enumerable).Assembly; | |
scriptOptions = scriptOptions.AddReferences(mscorlib, systemCore); | |
//Add namespaces | |
scriptOptions = scriptOptions.AddNamespaces("System"); | |
scriptOptions = scriptOptions.AddNamespaces("System.Linq"); | |
scriptOptions = scriptOptions.AddNamespaces("System.Collections.Generic"); | |
var state = await CSharpScript.RunAsync(@"var x = new List(){1,2,3,4,5};", scriptOptions); | |
state = await state.ContinueWithAsync("var y = x.Take(3).ToList();"); | |
var y = state.Variables["y"]; | |
var yList = (List)y.Value; | |
foreach(var val in yList) | |
{ | |
Console.Write(val + " "); // Prints 1 2 3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment