文件包含一些字符串,如:
abc 4 2
def 1 1 1
Gh 0
有一些LINQ功能,这个功能的细节并不那么重要
IEnumerable<List<int>> F() {
return File.ReadLines("input.txt")
.Select(a => a.Split(' ').Skip(1).Select(int.Parse).ToList())
.Where(a => a.Count >= 2)
.Take(3).OrderBy(a => a.Sum())
.Select(a => { Console.Write(a[0]); return a; });
}
Run Code Online (Sandbox Code Playgroud)
此功能不会向控制台输出任何内容.为什么?
代码如下:
func Contain(livesJSON []LiveJSON, single db.Live) bool {
for _, json := range livesJSON {
if json.Start == single.Time && json.Team == single.HomeTeamId {
return false
} else {
return true
}
}
}
Run Code Online (Sandbox Code Playgroud)
我和return
两个都有.if
else
我有一个对象列表,其中每个对象都有一个名为“频率”的属性,我希望能够选择频率最高的前 10 个对象。
我看到了一些类似于我希望使用 LINQ 解决的解决方案,因此我们不胜感激。
我有一个数组,例如
int[] array = new int[] {1, 3, 2, 3};
Run Code Online (Sandbox Code Playgroud)
问题是从数组中获取多个最大值的索引。
我想重构代码以使用多态性而不是if-else。我可以用if .. else来做。但是我想在这里使用多态。
谁能告诉我吗?
public class Calculator
{
public int Calculate(int a, int b, Operation operation)
{
switch(operation)
{
case "add":
return a+b;
case "subtract":
return a-b;
case "multiply":
return a*b;
default:
throw new Exception("Unknown Operation Type");
}
}
public class Operation
{
public string Type { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我已经看到太多不等于null的检查,如下所示:
if (receivedRequest != null && receivedRequest.Status != null)
Run Code Online (Sandbox Code Playgroud)
有没有更干净的方式来写这样的东西?
我是新手,并试图自己学习JavaScript.
有一个例子:
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
Run Code Online (Sandbox Code Playgroud)
我只是想知道符号"||"是什么 做?谢谢!感谢您的帮助.
当我尝试在我的程序中验证电子邮件和电话号码时,我有这样的例外。
错误:正则表达式写得正确,我不知道问题出在哪里。
我读了最后一篇文章,但在我的情况下有任何工作。
消息:System.ArgumentException:解析 '{2}[0-9]-{3}[0-9]' - 量词 {x,y} 不带任何东西。
public class Order
{
public string EmailValidationPattern = "{2}[0-9]-{3}[0-9]";
public string ZipCode { get; set; }
public string PhoneNumber { get; set; }
private void SetZipCode(string zipCode)
{
if (Regex.Match(zipCode, EmailValidationPattern).Success)
{
ZipCode = zipCode;
}
}
private void SetPhoneNumber(string number)
{
if (Regex.Match(number, @"^(\+[0-9]{9})$").Success)
{
PhoneNumber = number;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我一直在尝试制作一个将秒数转换为小时/分钟/秒的网络应用程序,但没有运气.我根本无法弄清楚如何做到这一点,我创建了十几个c#项目,但没有一个适用于我尝试的任何代码,我也不理解这样的事情的创建.如果有人能帮我创建这个表单,我将不胜感激.
我创建了一个 mvc 应用程序,我不想对应用程序中的一项功能进行身份验证。我希望用户能够在不登录的情况下从 URL 打开页面。现在,如果我输入 URL 直接打开该功能,那么它将带我进入登录页面。我想在一项功能中绕过身份验证过程。我在 web.config 中尝试了以下代码。
<location path="ControllerName">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Run Code Online (Sandbox Code Playgroud)
我还向控制器的某些操作添加了 [AllowAnonymous] 属性。
以下代码是我在 web.config 中编写的用于身份验证的代码。
<modules runAllManagedModulesForAllRequests="true">
<remove name="FormsAuthentication"/>
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule"/>
<remove name="AuthorisationModule"/>
<add name="AuthorisationModule" type="ProjectName.AuthorisationModule(which is for autentication), Project Name"/>
</modules>
Run Code Online (Sandbox Code Playgroud) 为什么它返回0?
print(70 * (50 / 100));
Run Code Online (Sandbox Code Playgroud)
70*0,5 = 35
我不知道为什么会这样.或者我犯了一些愚蠢的错误......我不知道
我的守则
static int IntCheck(string num)
{
int value;
if (!int.TryParse(num, out value))
{
Console.WriteLine("I am sorry, I thought I said integer, let me check...");
Console.WriteLine("Checking...");
System.Threading.Thread.Sleep(3000);
Console.WriteLine("Yup, I did, please try that again, this time with an integer");
int NewValue = IntCheck(Console.ReadLine());
}
else
{
int NewValue = value;
}
return NewValue;
}
Run Code Online (Sandbox Code Playgroud)
错误
当前上下文中不存在名称"NewValue"(第33行)
c# ×10
asp.net ×2
linq ×2
.net ×1
go ×1
ienumerable ×1
javascript ×1
list ×1
syntax ×1
unit-testing ×1