-2
PartDocument prtDoc = (PartDocument)CATIA.ActiveDocument;
Part part1 = prtDoc.Part;

Can anyone explain what the above two lines of code will do?

DerStarkeBaer
  • 669
  • 8
  • 28
  • I am new to MACROS. I record the macro in CATIA and try to edit in VisualStudio. So, I am trying to understand from basics. Can you tell me when to need typecast? For instance in the line below OriginElements originElements1 = (OriginElements)part1.OriginElements; IT was saying that the cast is redundant. – Yerramreddy Vamsidhar Reddy Nov 29 '19 at 11:04
  • 1
    Your question is pretty unclear. We don´t know what you already know about programming in general. E.g. do you know what a class is? What a property is? What a cast is? All those things are shown in your code, however we don´t know where **specifically** you´re struggling. – MakePeaceGreatAgain Nov 29 '19 at 11:06
  • I am struggling when to typecast and when not to do while using macros – Yerramreddy Vamsidhar Reddy Nov 29 '19 at 11:09
  • 1
    I don´t what what `ActiveDocument` is, but I suppose it´s not defined as `PartDocument` at compile-time. That´s why you need a cast. – MakePeaceGreatAgain Nov 29 '19 at 11:17
  • Possible duplicate of https://stackoverflow.com/questions/1339482/typecasting-in-c-sharp – MakePeaceGreatAgain Nov 29 '19 at 11:18
  • By the way: whoever "IT" is - maybe ReSharper ?? - when "IT" sais the cast is redundant you can surely omit it as it is meaningless. – MakePeaceGreatAgain Nov 29 '19 at 11:20

1 Answers1

0

I assume that you are asking about type conversion. You should get to know the concepts of implicit conversion, explicit conversion and strong typing. You can check which type is returned by given code, in your case CATIA.ActiveDocument; and with knowledge from above, you will know

when to typecast and when not to do

You can learn more about C# typing from official documentation here

burgund
  • 357
  • 1
  • 5
  • 12