TheSwamp
Code Red => .NET => Topic started by: It's Alive! on August 31, 2007, 01:18:48 PM
-
I wrote my first C# lambda expression today and it worked.. :|
For those who are interested, the C# 3.0 specification has been published
http://msdn2.microsoft.com/en-us/vcsharp/default.aspx
seems they added a ton of stuff to the language and to .NET 3.5 , more stuff to learn
using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace cSharpTest
{
public class SoSharp
{
[LispFunction("test1")]
public static void DoTest1(ResultBuffer Args)
{
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
List<TypedValue> list = new List<TypedValue>(Args.AsArray());
list.ForEach ( p => ed.WriteMessage(p.ToString()));
}
}
}
-
here is a fun one
//(test2 64)
[LispFunction("test2")]
public static void DoTest2(ResultBuffer Args)
{
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
List<TypedValue> list = new List<TypedValue>(Args.AsArray());
Func<UInt64, UInt64> Factorial = null;
Factorial = (n) => n <= 1 ? 1 : n * Factorial(n - 1);
ed.WriteMessage("{0}", Factorial(Convert.ToUInt64(list[0].Value)).ToString());
}
9223372036854775808
-
44616E69656C;
Can this beta be use with AutoCAD 2007 ?
-
I've had it installed for a while, but haven't made the time to play yet Daniel ... looks like you're having fun !
-
44616E69656C;
Can this beta be use with AutoCAD 2007 ?
Yes, that’s what version I was testing on. Since it’s still beta, I just stuck it on my laptop but I haven’t had any problems.
-
I've had it installed for a while, but haven't made the time to play yet Daniel ... looks like you're having fun !
Yes, I think it’s pretty cool so far, I just hope they don’t make the language so feature full that it becomes bloatware.
-
You can now target a specific framework in your project. In this function I targeted the 2.0 framework
static void Main(string[] args)
{
var TypedValueList = new List<KeyValuePair<int, int>>();
for (int i = 0; i < 10; i++)
{
for (int x = 0; x < 10; x++)
{
TypedValueList.Add(new KeyValuePair<int, int>(x, i));
}
}
var eList = TypedValueList.FindAll
(pairs => pairs.Key == 0 && pairs.Value > 5).GetEnumerator();
while (eList.MoveNext())
{
Console.WriteLine("\n{0}", eList.Current);
}
Console.ReadKey();
}
And reflector picked up this
private static void Main(string[] args)
{
List<KeyValuePair<int, int>> TypedValueList = new List<KeyValuePair<int, int>>();
for (int i = 0; i < 10; i++)
{
for (int x = 0; x < 10; x++)
{
TypedValueList.Add(new KeyValuePair<int, int>(x, i));
}
}
List<KeyValuePair<int, int>>.Enumerator eList = TypedValueList.FindAll(delegate (KeyValuePair<int, int> pairs) {
return (pairs.Key == 0) && (pairs.Value > 5);
}).GetEnumerator();
while (eList.MoveNext())
{
Console.WriteLine("\n{0}", eList.Current);
}
Console.ReadKey();
}
So it seems that some of the new language features are backwards compatible with older frameworks
-
This is the same as above but I am using LinQ to query an in-memory collection using an extension method with a lambda expression. :lol:
static void Main(string[] args)
{
var TypedValueList = new List<KeyValuePair<int, int>>();
for (int i = 0; i < 10; i++)
{
for (int x = 0; x < 10; x++)
{
TypedValueList.Add(new KeyValuePair<int, int>(x, i));
}
}
Func<KeyValuePair<int, int>, bool>
Filter = pairs => pairs.Key == 0 && pairs.Value > 5;
var eList = TypedValueList.Where(Filter).GetEnumerator();
while (eList.MoveNext())
{
Console.WriteLine("\n{0}", eList.Current);
}
Console.ReadKey();
}
-
LinQ ..
That reminds me of something I bookmarked recently
http://www.albahari.com/linqpad.html
and while I'm at it ...
' Reflexil is an assembly editor and runs as a plug-in for Lutz Roeder's Reflector. '
http://sourceforge.net/project/showfiles.php?group_id=200895
edit: Fixed lazy Sunday spelling ..
-
Yes, I think it’s pretty cool so far, I just hope they don’t make the language so feature full that it becomes bloatware.
Now that's an optimist. After all this time, still hoping to see non-bloatware out of Microsoft... :-D
-
This may be worth bookmarking ..
Jomo Fisher -- C#, LINQ and Whatnot
http://blogs.msdn.com/jomo_fisher/archive/2007/07/23/the-least-you-need-to-know-about-c-3-0.aspx
FrontPage:
http://blogs.msdn.com/jomo_fisher/default.aspx
added/edit: links changed