简体   繁体   English

尝试创建一个将读取文件值并返回它的 DLL

[英]Trying to create a DLL that will read a file value and return it

I am trying to create a DLL in any language (using Visual Studio is preferred), that will read a value from a file (file will only have that single value) and then return it in the function.我正在尝试使用任何语言创建一个 DLL(首选使用 Visual Studio),它将从文件中读取一个值(文件将只有该单个值),然后在函数中返回它。 I am not very familiar with DLLs and I'm not quite sure how they work, but I need this for my project, any help would be hugely appreciated.我对 DLL 不是很熟悉,我不太确定它们是如何工作的,但我的项目需要它,任何帮助将不胜感激。 Thanks谢谢

This example will be in C# (Part of Visual Studio Community Edition)此示例将使用 C#(Visual Studio 社区版的一部分)

Create a class library project & include the following method in your class:创建一个类库项目并在您的类中包含以下方法:

public static string getText(string filePath) 
{
     using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
     {
         using (TextReader tr = new StreamReader(fs))
         {
             return tr.ReadToEnd();
         }
     }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM