如何在classlibrary.cs中编写"hello world" [英] how to write 'hello world' in classlibrary.cs

查看:113
本文介绍了如何在classlibrary.cs中编写"hello world"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在classlibrary.cs这个简单的程序中编写"hello world",以便使自己了解如何完成操作,并进一步在工程中使用dll进行使用.我想要一个基本程序.

how to write ''hello world'' in classlibrary.cs ,simple program so as to make myself understand how it is done and further make dll and use in project.i want a basic program.

推荐答案

您已经在这里
You have already asked it over here, want basic code for class library function and how to implement namespace.[^]
So, you could have wait for few time to some one respond.
If you check out the link I have provided, has step by step explanation.

Create a Class Library Project > Write a Method

Public Class MyClassLibrary
    {
      public static string MyHelloMethod()
         {
            return "Hello World";
         }

    }



生成dll.将项目添加为对调用项目的引用.

如果名称空间与其他项目不同,则添加该名称空间.

然后,



Build the dll. Add the project as reference to the calling project.

Add the namespace if its different projects.

Then,

Console.WriteLine(MyClassLibrary.MyHelloMethod())

;

这将在您的输出屏幕上打印"Hello World".

注意,我使用了静态方法,直接调用而没有创建对象.希望您知道.

;

This will print, "Hello World" in your output screen.

Note, I used the static method, to directly call with out creating object. Hope you know that.


为此,您必须编写dll 调用程序集(exe).

尝试首先将hello world编程为例如控制台应用程序.可以的话,将一个类库项目添加到您的解决方案中,在您的控制台应用程序解决方案中对其进行引用,在dll中创建一个类,在该类中您可以将hello world代码放入方法中.

之后,在控制台应用程序中确定该类并调用该方法.运行时,使用调试器查看每一步的情况.
In order to do that you have to write the dll and the calling assembly (exe).

Try first programming the hello world for example to a console application. When that''s fine, add a class library project to your solution, reference it in your console application solution, create a class in the dll where you place the hello world code in a method.

After that istantiate the class in the console application and call the method. While running, use the debugger to see what''s happening at each step.


这篇关于如何在classlibrary.cs中编写"hello world"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆