gpt4 book ai didi

c# - 如果字符串为空则跳行

转载 作者:太空宇宙 更新时间:2023-11-03 23:30:35 25 4
gpt4 key购买 nike

如果字符串为空,我想跳过一行。

我这样试:

public void ReadPostedData()
{
Sender = HttpContext.Current.Request.Form["MailFormSubmitter_sender"];
Subject = HttpContext.Current.Request.Form["MailFormSubmitter_subject"];
Message = HttpContext.Current.Request.Form["Message"];
PdfMessage = HttpContext.Current.Request.Form["PdfMessage"];

string IsCheckPDfMailSubmit = HttpContext.Current.Request.Form["IsCheckedPDFMailForm"];
if (IsCheckPDfMailSubmit == null || IsCheckPDfMailSubmit.Length == 0)

//string.IsNullOrEmpty(IsCheckPDfMailSubmit);

return IsCheckPDfMailSubmit == null;

IsCheckedPDFMailForm = IsCheckPDfMailSubmit.Equals("True", StringComparison.OrdinalIgnoreCase);

string v = HttpContext.Current.Request.Form["MailFormSubmitter_includeoverviewpdf"];
IncludeOverviewPdf = v.Equals("true,false", StringComparison.Ordinal) ? true : false;
// http://forums.asp.net/t/1314753.aspx

ApplicantMailNodeSelectors[0] = HttpContext.Current.Request.Form["MailFormSubmitter_applicantemailaddress1"];
ApplicantMailNodeSelectors[1] = HttpContext.Current.Request.Form["MailFormSubmitter_applicantemailaddress2"];
ApplicantMailNodeSelectors[2] = HttpContext.Current.Request.Form["MailFormSubmitter_applicantemailaddress3"];
}

是关于这一行的:

if (IsCheckPDfMailSubmit == null || IsCheckPDfMailSubmit.Length == 0)

如果为空,则不执行此行:

IsCheckedPDFMailForm = IsCheckPDfMailSubmit.Equals("True", StringComparison.OrdinalIgnoreCase); 

我这样试:

return IsCheckPDfMailSubmit == null;

但随后出现以下错误:

Error 6 Since 'Seneca.SfsLib.Connectors.MailFormSubmitterModel.ReadPostedData()' returns void, a return keyword must not be followed by an object expression

那么如何跳过呢?

最佳答案

如果你想根据 if 语句中的条件退出函数,你只需使用 return; 当方法有 void 作为返回类型:

if (IsCheckPDfMailSubmit == null || IsCheckPDfMailSubmit.Length == 0) {
return;
}

或者,您可以反转条件并将其余代码放在 if 语句中,而不是在函数中间退出:

if (!(IsCheckPDfMailSubmit == null || IsCheckPDfMailSubmit.Length == 0)) {
// ...
// rest of the code in the method
// ...
}

如果您只是想跳过下面这行而继续使用方法中的其余代码,请反转条件并将该行放在 if 语句中:

if (!(IsCheckPDfMailSubmit == null || IsCheckPDfMailSubmit.Length == 0)) {
IsCheckedPDFMailForm = IsCheckPDfMailSubmit.Equals("True", StringComparison.OrdinalIgnoreCase);
}

关于c# - 如果字符串为空则跳行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32379284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com