private void Form1_MouseMove(object sender, MouseEventArgs e)
{
//Create Graphics
Graphics g = this.CreateGraphics();
mx = Math.Floor(e.X / 32);
my = Math.Floor(e.Y / 32);
}
Run Code Online (Sandbox Code Playgroud)
在Floorin mx和my(mx和我都是整数)下得到一个错误
错误:严重级代码描述项目文件行抑制状态错误CS0121以下方法或属性之间的调用不明确:'Math.Floor(十进制)'和'Math.Floor(double)'GameAttempt3 c:\ users\levyjrdesktop\documents\visual studio 2015\Projects\GameAttempt3\GameAttempt3\Form1.cs 95 Active
从昨天起我一直在努力更新以下查询,但没有运气.
在下面的查询,我需要更换int idSiteno有int[] SelectedidSiteno-你看到的int数组代替INT.
我尝试了.Contains .Any几乎所有的东西,但没有办法接近解决方案.你能帮忙吗?
ICollection<Department> dbList = _db.Departments
.Include(l => l.Sites)
.Where(l => l.idCompany == idCompany && l.Disabled == "N"
&& l.Sites.Any(x => x.idSite == idSiteno))
.OrderBy(l => l.SortOrder).ToList();
Run Code Online (Sandbox Code Playgroud) 在我的输入中跟随字符串
"(((5292-5325)-(5401/5))/5325)"
Run Code Online (Sandbox Code Playgroud)
我需要计算这一个,并希望得到输出float.对于我以前string来float转换,但我得到了异常.怎么做那个?
我想翻译一下:
foreach(Control c in Controls)
{
if(c is TextBox)
{
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
成:
foreach(Control c => (c is TextBox) in Controls)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
如何使用lambda函数专门完成?
下面我有一段代码可以从一段文本中提取数字值.所以,如果我有字符串+12 is on same day,那么它将提取12.
但是,如果我有一个负数,-12 is on the same day,我希望它提取-12,而不是12.
我如何提取减号?
foreach (char c in alternativeAirportPrice.Text)
{
if (char.IsNumber(c))
{
string test = "-12 on same day";
string alternativeAirportPriceValue = string.Join("", test.ToCharArray()
.Where(x => char.IsDigit(x)).ToArray());
return alternativeAirportPriceValue;
}
}
Run Code Online (Sandbox Code Playgroud) 我想说我正在用简单的编码学习语言.
如果我创建一个对象ResourceTemplate作为
public class ResourceTemplate
{
public string Name;
public int Value;
}
Run Code Online (Sandbox Code Playgroud)
然后做了
List<ResourceTemplate> resource = new List<ResourceTemplate>();
Run Code Online (Sandbox Code Playgroud)
该资源将是一个具有结构的列表ResourceTemplate.如果是这样,为什么我不能使用 resource.Add("product", 500);?
编译器说它不能对ResourceTemplate函数进行重载.
我最近接受了一个项目作为个人爱好,以提高我的代码质量.我已经制作了这个方法,但我觉得我肯定是以某种方式工作了,我觉得有一种非常简单的方法可以做到这一点,而不必像这样一个大的开关?
我知道0-9可能只是.ToString()'然后解析为int并返回,但我不确定如何合并这个想法,同时还考虑其余的开关案例.
public static short ParseHeight(char input)
{
switch (input)
{
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case 'a':
return 10;
case 'b':
return 11;
case 'c':
return 12;
case 'd':
return 13;
case 'e':
return 14;
case 'f':
return 15;
case 'g':
return …Run Code Online (Sandbox Code Playgroud) 我需要启动一个秒表,然后在另一个类中停止它,然后检索已经过去的时间。当我在OnSignIn方法中创建秒表对象时,它看不到方法中对象的创建OnSignOut。我应该如何解决这个问题?
public void OnSignIn(int pin)
{
if (this.pin == pin && this.SignIn == false)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
}
else if (this.pin != pin)
{
MessageBox.Show("Incorrect pin or already logged in");
}
}
public void OnSignOut (int pin)
{
if (this.pin == pin && this.SignIn == true)
{
stopwatch.Stop();
}
else
{
MessageBox.Show("Error!");
}
}
Run Code Online (Sandbox Code Playgroud) 我有2个List<Animal>我想比较并找到2个List<Animal>对象之间的区别.
Animal object包含以下属性.
ID
名称
年龄
List中list1有10个Animal对象,其中list2有10个Animal对象.在这2个列表中有2个项目(Animal对象相同)
当我使用该Except函数时,我希望remainingList它只包含2列表中不常见的对象.但是,remainingList包含一个副本list1.
我怎么解决这个问题?
List<Animal> remainingList = list1.Except(list2).toListAsync();
Run Code Online (Sandbox Code Playgroud) 我有以下代码
int[] array = new int[10] { 4, 50 , 60 , 80 , 120 , 46 , 52 , 60 , 18 , 221};
var sum = (from num in array
where ((num % 4) != 0 && (num % 6 ) != 0) && ((num % 2) != 0)
select array);
Console.Write(sum.Sum());
Run Code Online (Sandbox Code Playgroud)
问题是我无法使用Sum().它说
'System.Collections.Generic.IEnumerable'不包含'Sum'的定义和最佳扩展方法重载'System.Linq.Queryable.Sum(System.Linq.IQueryable)'
我怎么能这样做?