Can C# compiler compile a VB.Net code?

后端 未结 4 1976
离开以前
离开以前 2021-01-05 14:46

I found following on a ASP.NET book. I am learning and curious about following content.

The second major advantage of an IL architecture is that it en

4条回答
  •  遥遥无期
    2021-01-05 15:37

    ASP.Net is a server-side Web application framework designed for Web development to produce dynamic Web pages.

    What you are confused is about the compilation of languages, now, C# and VB.Net has it's own compilers. ASP.Net is a framework that could be achieved using languages like C# and all.

    So do not get confused with language compilers. Each language will have their respective compilers that will convert the source code to a Intermediate language (IL) code that the Common Language Runtime (CLR) can understand. So a web framework like ASP.net is a framework that provides a mechanism to process the HTTPRequest and HTTPResponse. Now the language compilers will do their part of work of compiling respective programming language to IL code.

    From MSDN:

    ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web applications with a minimum of coding. ASP.NET is part of the .NET Framework, and when coding ASP.NET applications you have access to classes in the .NET Framework. You can code your applications in any language compatible with the common language runtime (CLR), including Microsoft Visual Basic and C#. These languages enable you to develop ASP.NET applications that benefit from the common language runtime, type safety, inheritance, and so on.

    Update:

    Now answering the second doubt that you posted in the commenting section of your question. (Can C# compiler compile VB code)

    Actually you cannot. Let us consider C# compiler, what any compiler like C# or VB know's is that you have certain code written in front of you and you need to understand the code and provide an equivalent IL code in this case. This means, a C# compiler has to work with code that has syntax of C# and a VB compiler has to work with code that has syntax of VB. You see a compiler basically needs to know what it is compiling (processing). Now consider some language X has a X compiler, now the compiler will be written in order to just crack and decode the language X.

    Now, this does not stop you from writing VB code that talks to C# code or vice versa. That interoperability. See more.

提交回复
热议问题