C# 委托人'System.Func<;布尔>';不接受'1';论据
当用户从登录活动输入密码并将其发送到登录服务时 并等待登录服务中的布尔响应。但给出上述语法错误(我在代码中提到过)可以解决我的问题。 我必须等待服务响应到达我的登录活动C# 委托人'System.Func<;布尔>';不接受'1';论据,c#,.net,C#,.net,当用户从登录活动输入密码并将其发送到登录服务时 并等待登录服务中的布尔响应。但给出上述语法错误(我在代码中提到过)可以解决我的问题。 我必须等待服务响应到达我的登录活动 Login.Click += async (object sender, EventArgs e) => { progress = ProgressDialog.Show (this, "", "Connecting..."); var isLoginSuccessful = loginAuthenti
Login.Click += async (object sender, EventArgs e) => {
progress = ProgressDialog.Show (this, "", "Connecting...");
var isLoginSuccessful = loginAuthenticator.AuthenticateUser
(password.Text, (value) => {
Console.WriteLine (value);
});//error
if (progress != null) {
progress.Dismiss ();
progress = null;
}
if (isLoginSuccessful) {
StartActivity (typeof(Ledger_HomeActivity));
this.Finish ();
} else {
Toast.MakeText (this, "Invalid Login credentials! try again", ToastLength.Short).Show ();
}
};
1.登录界面
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace RetailAppShared
{
public interface ILoginServices
{
bool AuthenticateUser (string passcode, Func<bool> function);
}
}
它看起来像是
函数
表示一个回调方法,您使用真
或假
的值调用该方法,并且该方法不会返回任何值。在这种情况下,您应该使用Func
,而不是Func
,因为Func
的作用正好相反-它不接受任何参数,并将bool
值返回给您。它看起来像function
代表一个回调方法,您使用true
或false
的值调用它,这不会给你带来任何价值。在这种情况下,您应该使用Func
,而不是Func
,因为Func
的作用正好相反-它不接受任何参数,并将bool
值返回给您。错误出现在这一行
var isLoginSuccessful = loginAuthenticator.AuthenticateUser (password.Text, (value) => { Console.WriteLine (value); }):
Func
返回布尔值,不需要任何内容。您需要的是一个操作
,该操作需要一个布尔值,但返回void
:
public bool AuthenticateUser (string passcode, Action<bool> function)
{
function(true);
}
public bool AuthenticateUser(字符串密码,动作函数)
{
函数(真);
}
错误出现在这一行
var isLoginSuccessful = loginAuthenticator.AuthenticateUser (password.Text, (value) => { Console.WriteLine (value); }):
Func
返回布尔值,不需要任何内容。您需要的是一个操作
,该操作需要一个布尔值,但返回void
:
public bool AuthenticateUser (string passcode, Action<bool> function)
{
function(true);
}
public bool AuthenticateUser(字符串密码,动作函数)
{
函数(真);
}
AFunc
类似于返回bool
但没有参数的方法。您应该像bool result=function()那样调用它代码>。相反,如果您希望传入一个bool
,并且没有返回值,则应该使用Action
。一个Func
类似于一个返回bool
但没有参数的方法。您应该像bool result=function()那样调用它代码>。如果您希望传入一个bool
,并且没有返回值,则应使用Action
。