我在允许使用我自己的代码扩展其功能的应用程序中使用它。不能隐式地将类型void转换为C#中的对象错误
它被编码在C#中。
Result()
将返回它从我的Node.js服务器(FinalResponse
)获取和我要访问它像下面的应用程序,但我得到的称号的错误,当我尝试使用EchoOut答案() 。
var returnedValue = Lib.Result();
App.EchoOut(returnedValue); // EchoOut allows you to test the function you wrote, it echoes string on the screen, but in this case, it gives an error.
错误
cannot implicitly convert type void to object
当我单独测试Lib.Result()
,我看到的请求是由该应用进行的,但我不能返回的值分配给变量。
如何将FinalResponse's
值分配给returnedValue
变量?
我的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace MainNameSpace
{
public class Lib
{
public void Result()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("192.168.1.101:8000/mytest");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader stream = new StreamReader(response.GetResponseStream());
string FinalResponse = stream.ReadToEnd();
Console.WriteLine(FinalResponse);
}
}
}
无效手段“这种方法有什么返回'而是你有一个方法需要返回一个字符串。 – Steve
谢谢,史蒂夫。它现在有效。 – salep