当我将它变成.dll时,为什么C#类库不起作用? [英] Why doesn't C# Class Library works when I make it an .dll?

查看:60
本文介绍了当我将它变成.dll时,为什么C#类库不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么.dll不起作用?



我使用下面的代码来调用它:

Why doesn't the .dll works?

I use the following code to call it:

using XauSHello;

HelloWorld hello = new HelloWorld();





当我写你好时。它没有给我我的功能谈话和说话。为什么?



这是类库cs文件:





When I write "hello." it doesn't give me my functions "Talk" and "Speak". Why?

This is the Class Library cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SpeechLib;
using System.Windows.Forms;

namespace XauSHello
{
    public class HelloWorld
    {
        public static void Talk(string p)
        {
            MessageBox.Show(p);
        }

        public static void Speak(string speak)
        {
            SpVoice Voice = new SpVoice();

            Voice.Rate = 1;
            Voice.Volume = 100;
            Voice.Speak(speak);
        }
    }
}

推荐答案

因为Talk和Spe​​ak是静态方法,所以你可以不要在实例上调用它们。为了看到它们,你必须使用HelloWorld.Talk()或HelloWorld.Speak,而不是hello.Talk或hello.Speak。
Because Talk and Speak are static methods, so you can't call them on an instance. In order to "see" them, you have to use HelloWorld.Talk() or HelloWorld.Speak, not hello.Talk or hello.Speak.


这篇关于当我将它变成.dll时,为什么C#类库不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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