if --else if --block包含许多if语句的最佳替代方法是什么.
码:
string word="";
if(letter=='a')
{
// do some action
call(a);
}
else if (letter=='b')
{
call(b)
}
else if (letter=='c')
{
call(c)
}
else if (letter=='d')
{
// do some action
call(d)
}
else if (letter=='e')
{
// do some action
call(e)
}
................
..............
else if (letter=='z')
{
// do some action
call(z)
}
Run Code Online (Sandbox Code Playgroud)
如果有很多if-else语句,那么找到这种场景的解决方案的最佳方法是什么.有没有办法使用类/对象有效地设计这样的场景?
我相信我们中的许多人在设计/编码过程中都会面临这样的问题.有没有一种有效的方法来处理这种情况?
没有开关声明请.使用C#对象的有效设计算法将是最好的选择.
我有两个列表对象.我将它们组合成一个列表.虽然合并我需要删除重复.TweetID是要比较的字段.
List<TweetEntity> tweetEntity1 = tt.GetTweetEntity(Convert.ToInt16(pno), qdecoded, longwoeid );
List<TweetEntity> tweetEntity2 = tt.GetTweetEntity(Convert.ToInt16(pno), qdecoded);
List<TweetEntity> tweetEntity = tweetEntity1.Concat(tweetEntity2).ToList();
Run Code Online (Sandbox Code Playgroud)
我已将两个列表合并,但无法过滤掉重复项.是否有任何内置函数来删除List <>中的重复项?
我有以下代码:
<div class="_GAb-_GAd">
<div class="_GANmb _GAe ACTION-removeFilter TARGET-1">clear</div>
</div>
<div class="_GAb-_GAd">
<div class="_GANmb _GAe ACTION-removeFilter TARGET-2">clear</div>
</div>
Run Code Online (Sandbox Code Playgroud)
和脚本(Jquery)
<script>
$(document).ready(function() {
$(".ACTION-removeFilter").click(function() {
alert('find out which TARGET is being clicked.');
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
我想知道点击了哪个TARGET(TARGET-1或TARGET-2).有没有办法找出来?
我怎么知道呢?
我有一个数组:
List<String> TagArray = new List<string>(TagString.Split(','));
Run Code Online (Sandbox Code Playgroud)
我想删除数组中的某些元素; 说 - 如果值包含字母'AAA'.
在C#中是否有一行语句可以实现所需的结果?
码:
string testquestions = "1,2,100,3,4,101,98,99";
string[] qidarray = testquestions.Split(',');
StringBuilder sb = new StringBuilder();
foreach (string s in qidarray)
{
sb.Append(String.Format(@"({0}),",s));
}
string output= sb.ToString().Substring(0, sb.ToString().Length - 1);
Run Code Online (Sandbox Code Playgroud)
期望的输出=
(1),(2),(100),(3),(4),(101),(98),(99)
Run Code Online (Sandbox Code Playgroud)
代码有效.我想知道这是实现结果的最佳方式.有没有更好的方法来达到预期的效果?
有没有办法不使用foreach循环?
我有以下代码:
examdate = Convert.ToDateTime(ttd.DateCreated).ToString("MMM dd yy");
Run Code Online (Sandbox Code Playgroud)
它返回 Jun 27 18
但我需要以下输出
Jun 27 '18
所以我将代码更改为
examdate = Convert.ToDateTime(ttd.DateCreated).ToString("MMM dd 'yy");
Run Code Online (Sandbox Code Playgroud)
它引发了一个错误:
Cannot find a matching quote character for the character '''.
我浏览到 abc.razor OnInitializedAsync() 方法被调用。
现在在 OnvalidSubmit 方法中我有以下代码
NavManager.NavigateTo("/abc?rid=1", false, true);
Run Code Online (Sandbox Code Playgroud)
这意味着它应该再次导航到 abc.razor 页面。它确实导航但不调用 OnInitializedAsync() 方法?
为什么这样?
当我在 azure-dev-ops 中运行管道时,出现这样的错误。
##[错误]C:\Program Files\dotnet\sdk\6.0.203\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5):错误NETSDK1005:资产文件'D:\a \1\s\BlazorAppDB\Server\obj\project.assets.json' 没有“net6.0”的目标。确保恢复已运行并且您已将“net6.0”包含在项目的 TargetFrameworks 中。
该项目是 blazor wasm 项目,可以从 Visual studio 2022 完美运行和发布 - 但是,当它从 azure-dev-ops 的管道运行时,我收到此错误
有人可以指出在哪里解决这个问题吗?我理解它更多的是配置错误而不是功能错误。
哪个查询运行得更快?
考虑到它返回200条记录并且authorname至少有20个字符并且authorname是全文索引的
select * from quotestable
where quotesauthor like (select Authorname from Authortable where authorid =45)
Run Code Online (Sandbox Code Playgroud)
.
select * from quotestable
where quotesauthor in (select Authorname from Authortable where authorid =45)
Run Code Online (Sandbox Code Playgroud) 我有以下 aspx 页面,例如:称为choosemenu.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<div id="renderhere" runat="server">render user control here </div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我有一个名为的 ascx 页面列表
english.ascx
commerce.ascx
maths.ascx
Run Code Online (Sandbox Code Playgroud)
我必须根据 aspx 页面中的查询字符串在我的 aspx 页面中动态加载 ascx 文件。
我在 page_load 事件中的 aspx 页面中有以下内容。
var control = (English)Page.LoadControl("/ascx/english.ascx");
Run Code Online (Sandbox Code Playgroud)
我将如何在此标记中的choosemenu.aspx 中呈现 english.ascx 页面的内容
另外我必须在 ascx 文件中传递一些值。这是静态的东西。
<Menu:MNU ID="english" runat="server" HiLiter="<%#h %>"></Menu:MNU>
Run Code Online (Sandbox Code Playgroud) 我的代码
string? SegroupOf;
if(SegroupOf.Contains("Team"))
{
}
Run Code Online (Sandbox Code Playgroud)
如果 SegroupOf 为 null,则会抛出错误。空值如何处理?我已将 SegroupOf 指定为可为空,如何确保即使其为空也不会引发任何错误
这是我的代码
public class SEWorkflow
{
public Dictionary<SETabs, bool> tabNVPair { get; set; }
}
public enum SETabs
{
Main,
Attachments,
TechTeamReview,
SecurityTeamReview,
TechTeamImplementation
}
//I am initialising like this...
List<SEWorkflow> result = new List<SEWorkflow>()
{
new SEWorkflow()
{
tabNVPair = new Dictionary<SETabs,bool>()
{
SETabs.Main = true,
SETabs.Attachments = true,
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误 // //Error CS0131 赋值的左侧必须是变量、属性或索引器
我将如何初始化?
c# ×8
.net ×1
asp.net ×1
azure-devops ×1
blazor ×1
c#-4.0 ×1
jquery ×1
linq ×1
sql ×1
sql-server ×1