Can you write a block of c++ code inside C#?

前端 未结 5 1084
执念已碎
执念已碎 2021-01-20 06:47

I heard somewhere that you can drop down to C++ directly inside C# code. How is this done? Or did I hear wrong?

Note: I do not mean C++ / CLI.

相关标签:
5条回答
  • 2021-01-20 06:50

    You can interact with COM objects very easily from .NET.

    0 讨论(0)
  • 2021-01-20 07:04

    You might be thinking of unsafe blocks where you can write code that looks a lot like C++, since you can use pointers.

    0 讨论(0)
  • 2021-01-20 07:09

    You heard incorrectly.

    0 讨论(0)
  • 2021-01-20 07:11

    You can drop down to Assembly from C, because C is instruction-set-semi-agnostic Assembly.

    You can drop down to C from C++, because C++ is C plus some other things that make it divinely ugly or horrifically beautiful, depending on your perspective.

    You can't drop down from C# to C++, because they are entirely different things. There is no direct relation between them, aside from the curly-brackets-and-semicolons syntax. C# is not a superset of C++, nor a subset of it, nor a sibling of it (but perhaps a second cousin).

    That said, C# provides facilities for interacting with external code at all levels of abstraction, from Platform-Invoke (calling functions written in C) to COM to a wide variety of other kinds. But C# itself is not directly related to these things.

    0 讨论(0)
  • 2021-01-20 07:12

    Why would you need to do that? You can reference native C libraries, but I doubt very much that you can run native code from within managed code.

    0 讨论(0)
提交回复
热议问题