Hi,
I have some experience in vb.net, now i'm learning c#. I tried to translate my vb.net code to c# but I get an error:
Cannot convert method group 'StartTransaction' to non-delegate type 'Autodesk.AutoCAD.DatabaseServices.Transaction'. Did you intend to invoke the method?
What am I doing wrong? Here is a code:
public ObjectId AddToModelSpace(Database DBIn, Entity EntityIn) { Document doc = Application.DocumentManager.MdiActiveDocument; using (DocumentLock acLckDoc = doc.LockDocument()) { using (Transaction myTrans = DBIn.TransactionManager.StartTransaction) { BlockTable myBT = DBIn.BlockTableId.GetObject(OpenMode.ForRead); BlockTableRecord myModelSpace = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite); myModelSpace.AppendEntity(EntityIn); myTrans.AddNewlyCreatedDBObject(EntityIn, true); myTrans.Commit(); return EntityIn.ObjectId; } } }
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
With C#, when you call a method without argument, you must explicitly write the empty argument list: ()
Transaction myTrans = DBIn.TransactionManager.StartTransaction()
This clearly differentiates calling to methods without argument and calling to properties. I also differentiates a calling to a function (to get the returned value) and the using of a delegate (passig the function name).