[Mono-list] CSharp interpreter feedback, and a gift

Bojan Rajkovic severedcross at gmail.com
Fri Jan 28 02:05:11 EST 2011

On Jan 27, 2011, at 9:52:35PM, Doug Blank wrote:

> It would be great to be able to have C# as one of the languages to use
> in this educational environment, but until it can address functions
> and classes, it will be a second-class citizen. Although, it will be a
> nice step for students to be able to take to see a fully-typed,
> explicit language---even as it is interpreted.
> If any one has suggestions about using C# in the educational
> environment, please let me know.
> -Doug

If you're willing to fake it, you can define functions as lambdas. It'll be ~= to defining them in a real sense.

Try something like this:

	Action<T> printMe = t => Console.WriteLine (t);

or in the more complex case (retrieving some content from a webserver that always returns GZip [yes, I did run into this while exploring some services via the REPL]):

	Func<string, string> doRequestWithPayload = payload => {
		var wc = new WebClient ();
		var data = wc.UploadData ("http://url:port/service", "POST", Encoding.UTF8.GetBytes (payload));
		return new StreamReader (new GZipStream (new MemoryStream (data), CompressionMode.Decompress)).ReadToEnd ();

It works perfectly well in the interpreter. It's not quite a real function definition, but it's close enough for most purposes. Classes on the other hand are a no-go.


More information about the Mono-list mailing list