Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use CSC.exe to combine module into assembly

Shulou Source: shulou.com Published: 2022-06-03 02:43:02 09月10日 Update

Editor to share with you how to use CSC.exe to combine module into assembly, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1. Create a new FrequentlyUsedCalculator.cs file

The code is as follows:

Using System;namespace MyClassLib {public class FrequentlyUsedCalculator {public int Add (int a, int b) {return a + b;} public int Sub (int a, int b) {return a-b;}} 2, compile the FrequentlyUsedCalculator.cs file csc.exe / t:module FrequentlyUsedCalculator.cs3, and create a new RarelyUsedCalculator.cs file

The code is as follows:

Using System;namespace MyClassLib {public class RarelyUsedCalculator {public int Multiple (int apenint b) {return a * b;} public int Divide (int a / b) {return a / b;}} 4, compile the RarelyUsedCalculator.cs file csc.exe / t:module RarelyUsedCalculator.cs

5. Merge the module file into the assembly file al.exe / out:MyClassLib.dll / t:library FrequentlyUsedCalculator.netmodule RarelyUsedCalculator.netmodule

6. Create a new Program.cs file using System;using MyClassLib;namespace MyConsoleApp {class Program {static void Main (string [] args) {Console.Write ("Please enter the first integer:"); int number1 = Convert.ToInt32 (Console.ReadLine ()); Console.Write ("enter the second integer:"); int number2 = Convert.ToInt32 (Console.ReadLine ()) FrequentlyUsedCalculator cal1 = new FrequentlyUsedCalculator (); Console.WriteLine ("{0} + {1} = {2}", number1, number2, cal1.Add (number1, number2)); Console.WriteLine ("{0}-{1} = {2}", number1, number2, cal1.Sub (number1, number2)); RarelyUsedCalculator cal2 = new RarelyUsedCalculator () Console.WriteLine ("{0} * {1} = {2}", number1, number2, cal2.Multiple (number1, number2)); Console.WriteLine ("{0} / {1} = {2}", number1, number2, cal2.Divide (number1, number2)); Console.ReadKey () 7. Compile Program.cs csc.exe / out:Program.exe / t:exe / r:MyClassLib.dll Program.cs

8. Running result

The above is all the content of the article "how to use CSC.exe to combine module into assembly". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Files articles compilation code content integers input not much most more knowledge results industry information information channels channels and into reference learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info Apple Huawei NVidia