在我的应用程序中,我遇到了以下结果,并对结果感到惊讶:
8/-7=-2 (两个整数).
这意味着什么?
在我的桌面C#应用程序中,我从字典开始.我希望能够检查这个字典中的密钥.如果字典有这个键,我想把它传递给一个方法.如果字典没有这个键,我想创建一个空白列表,然后将其传递给它.我怎样才能做到这一点?
我收到错误"给定密钥不在字典中".我可以添加一个默认值,因此它永远不会为null吗?
// myDic was declared as a Dictionary<string, List<string>
// Here is how I call someFunction
string text = SomeFunction(stringValue1, stringValue2, myDic[field1.field2]);
// SomeFunction looks like this
string SomeFunction (string string1, string string2, List<string> ra)
{
// method
return stringResult;
}
Run Code Online (Sandbox Code Playgroud) 我在C#中创建一个.NET线图,X轴间隔为几周.对于我的项目,我只想使用自定义标签,但是现在我仍然需要网格线.有没有人知道在保留自定义标签的同时隐藏默认X轴标签的方法?
我试过这个:
Chart4.ChartAreas[0].AxisX.LabelStyle.Enabled = false;
Run Code Online (Sandbox Code Playgroud)
显而易见的结果是没有应用标签,这不是我想要做的.
编辑: 生成原始行的代码是这样的:
Chart4.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "M";
Run Code Online (Sandbox Code Playgroud)
自定义标签的代码是这样的:
int month = XValues[0].Month;
var XAxis = Chart4.ChartAreas[0].AxisX;
DateTime StartMonthPos = XValues[0];
DateTime EndPos = new DateTime();
foreach (DateTime Date in XValues)
{
EndPos = Date;
if (Date.Month != month)
{
Chart4.ChartAreas[0].AxisX.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 1, LabelMarkStyle.None);
StartMonthPos = Date;
}
month = Date.Month;
}
XAxis.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 1, LabelMarkStyle.None);
Run Code Online (Sandbox Code Playgroud)
该图表如下所示: 
它看起来应该是这样的: 
请查看Linqpad中的以下代码,并告诉我为什么它返回0项而不是1项.
void Main()
{
string[] strArray = {"apple", "banana", "cherry", "e"};
List<string> lst = strArray.ToList();
//count all occurences of variable alphabet "e" in LINQ
//tip is to get the occurences of letter "e" in each word
// and then total them together
var lst2 = lst.TakeWhile(c=>c.Equals("banana")).Select(c=>c);
Console.WriteLine(lst2);
}
Run Code Online (Sandbox Code Playgroud)
上面的代码没有像我期望的那样在linqpad中返回1个项目.相反,它返回0项.带有1个项目"banana"的列表应该返回.为什么不呢?
计算机和播放器的赢率始终为0%或100%,我不知道为什么.我已经逐步完成了这个问题,似乎没有任何问题,但它没有像我期望的那样工作,因此必定存在某些问题.
abstract class Participant
{
public int wins;
float _winRate;
protected float winRate {
get
{
return _winRate;
}
set
{
if (value < 0 || value > 100)
{
throw new Exception("value cannot be less than 0 or greater than 100");
}
_winRate = value;
}
}
public void PrintWinRate()
{
winRate = (wins / Game_Info.gamesPlayed) * 100;
string _winRate = "win rate: " + winRate.ToString() + "%";
Console.WriteLine(_winRate.PadLeft(0));
}
public abstract string Choice();
}
class Computer:Participant
{
string[] …Run Code Online (Sandbox Code Playgroud) c# ×4
.net ×1
axis-labels ×1
charts ×1
dictionary ×1
division ×1
linechart ×1
linq ×1
list ×1
python ×1