嗨那里第一次使用stackoverflow所以嗨每一个L)
我是C#表单的初学者,我认为这是一个有趣的爱好.
SqlCommand comm = new SqlCommand("SELECT COUNT(*) FROM Members where sponser = "
+textbox1.text+"'", connection);
Int32 count = (Int32)comm.ExecuteScalar();
textbox2.Text ="Found "+ count+" Members;
Run Code Online (Sandbox Code Playgroud)
好吧它只是我从谷歌xD得到的两个代码之间的混合如何错误出现在这里textbox2.Text ="找到"+计数+"成员;
我需要使用两个数组进行Reverse Intersection操作,并将结果保存在不同的数组中
例如:数组A {1,2,3}; 数组B {1,2,3,4,5,6}结果数组应为{4,5,6}
我试过以下逻辑,但没有奏效
int k = 0;
int a[2] = {1,10};
int p[10];
int roll[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (int i = 0; i < 2; i++)
{
for (int j = 1; j <= 10; j++)
{
if (a[i] == roll[j])
{
break;
}
else
{
p[k] = 0;
p[k] = roll[j];
k++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的vb.net项目需要它
我是明确构建LINQ表达式的新手,我试图通过使用Aggregate和Expression.AndAlso来弄清楚如何将IEnumerable >>组合成单个Expression>.
我觉得我越来越近了,但我显然错过了一些东西.
public static Expression<Func<T, bool>> CombineExpressions<T>(
IEnumerable<Expression<Func<T, bool>>> expressions)
{
if (expressions == null || expressions.Count() == 0)
{
return t => true;
}
var combined = expressions
.Cast<Expression>()
.Aggregate((a, b) => Expression.AndAlso(a, b));
ParameterExpression pe = Expression.Parameter(typeof(T), "x");
return Expression.Lambda<Func<T, bool>>(combined, pe);
}
Run Code Online (Sandbox Code Playgroud)
当我调用此方法时,我得到以下异常:
System.ArgumentException:
Expression of type 'System.Func`2[SomeEntity,System.Boolean]'
cannot be used for return type 'System.Boolean'
Run Code Online (Sandbox Code Playgroud)
请帮忙!
我写了一个猜测1-100之间的数字游戏.这是我的代码..
class Program
{
static void Main(string[] args)
{
while (true)
{
int randno = Newnum(1, 101);
int count = 1;
while (true)
{
Console.Write("Guess a number between 1 and 100, or press 0 to quit: ");
int input = Convert.ToInt32(Console.ReadLine());
if (input == 0)
return;
else if (input < randno)
{
Console.WriteLine("Unlucky, that number is too low - have another go!");
++count;
continue;
}
else if (input > randno)
{
Console.WriteLine("Unlucky, that number is too high - have another …Run Code Online (Sandbox Code Playgroud) 我一直试图在任何地方找到这个答案,并且觉得我一定不知道我需要的正确关键词,所以我希望在这里找到答案.
所以我正在建立一个连接的项目:
数据库<>数据层<>逻辑层<> UI
当数据进入逻辑层时,我试图进行轻微的转换.首先,我将演示代码,然后解释我正在尝试做什么.
我在数据层中有一个'PersonDao'对象,具有以下设置:
public class PersonDao
{
public int PersonID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int GenderID { get; set }
}
Run Code Online (Sandbox Code Playgroud)
和一个'GenderDao'对象具有以下内容:
public class GenderDao
{
public int GenderID { get; set; }
public string Name { get; set; } //this essentially holds 'male' and 'female'
}
Run Code Online (Sandbox Code Playgroud)
在逻辑层中,我在逻辑层中有一个镜像数据层的'PersonDto'对象:
public class PersonDto
{
public int PersonID { get; set; }
public string FirstName …Run Code Online (Sandbox Code Playgroud) 我是C sharp Programming的新手,我坚持使用一个程序来开发一个类似于计算器的程序,它将用户的输入转换为一个名为choice的int数据类型,它将读取用户的两个操作数,然后计算将执行一个开关循环,根据所选的选项执行所需的操作,并给出输出结果.显示结果并打破案例后,程序将询问用户是否继续,反馈将存储在将被比较的字符变量,如果选择Y,它将把程序的执行重定向到开始标签.以下是相同的代码:
public static void Main(string[] args)
{
int choice,op1,op2;
char ch;
start:
Console.WriteLine("Enter First Operand");
op1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Second Operand");
op2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter your Input \n1. For Addition \n2.For Subtraction \n3.For Multiplication \n4.For Division");
choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
Console.WriteLine(op1+op2);
break;
case 2:
Console.WriteLine(op1 - op2);
break;
case 3:
Console.WriteLine(op1*op2);
break;
case 4:
Console.WriteLine(op1/op2);
break;
default:
Console.WriteLine("Please enter valid Choice");
break;
}
end:
Console.WriteLine("Do you want to Continue(Y/N)?");
ch=Convert.ToChar(Console.Read());
if (ch == 'Y') …Run Code Online (Sandbox Code Playgroud) 我正在尝试在linq中执行多个where子句,如下所示:
.Where(x => x.Division == item.Division)
.Where( x => x.ProductID == item.ProductID)
.Where( x => item.supplierNumber == item.supplierNumber)
.Where(x => item.OpcoID == item.OpcoID);
Run Code Online (Sandbox Code Playgroud)
当我吐出SQL时,它看起来像这样
WHERE ( ( [extent1].[Division] = @p__linq__0 )
OR ( ( [extent1].[Division] IS NULL )
AND ( @p__linq__0 IS NULL ) ) )
AND ( ( [extent1].[ProductID] = @p__linq__1 )
OR ( ( [extent1].[ProductID] IS NULL )
AND ( @p__linq__1 IS NULL ) ) )
AND ( ( @p__linq__2 = @p__linq__3 )
OR ( ( @p__linq__2 IS …Run Code Online (Sandbox Code Playgroud) 我有这个LINQ可以完成我想要的工作
var query = context.MasterTemplateOfficeTag
.Join(context.Tag, x => x.TagId, y => y.Id, (x, y) => new { y.Name })
.ToList();
Run Code Online (Sandbox Code Playgroud)
虽然我的问题是我希望LINQ返回一个,list<String>因为Select语法=> new { y.Name })是类型的string.因此如果编译器知道返回类型,为什么我不能使用list<String>?
我想要这样的东西
List<String> name = context.MasterTemplateOfficeTag
.Join(context.Tag, x => x.TagId, y => y.Id, (x, y) => new { y.Name })
.ToList();
Run Code Online (Sandbox Code Playgroud)
这可能吗?
谢谢
使用下面的函数,我通过传递纬度(a),纬度(b),经度(a),经度(b),并使用下面给出的公式以公里为单位来计算两个陆地点之间的距离,但结果不是正确,我该如何解决?
代码C#:
public static double CalcoloDistinzaFra2PuntiTerrestri(double LatA, double LonA, double LatB, double LonB)
{
double tot = 0;
const double R = 6371;
const double pigreco = 3.1415927;
double lat_alfa, lat_beta;
double lon_alfa, lon_beta;
double fi, p;
lat_alfa = pigreco * LatA / 180;
lat_beta = pigreco * LatB / 180;
lon_alfa = pigreco * LonA / 180;
lon_beta = pigreco * LonB / 180;
fi = Math.Abs(lon_alfa - lon_beta);
p = Math.Acos(Sin(lat_beta) * Sin(lat_alfa) + Cos(lat_beta) * Cos(lat_alfa) * …Run Code Online (Sandbox Code Playgroud) 我第一次将表中的数据填充到列表中然后我清除列表以从不同的表中选择不同的数据,所以我希望从内存中释放第一个列表,因为我将越来越多地获得新数据.
我试过了:
List.Dispose();
List.Clear();
List = null;
GC.Collect();
Run Code Online (Sandbox Code Playgroud)
但记忆力充沛.
在实体框架中我想出来并添加了.AsNoTracking()它并且它工作并且内存被清除
但我必须使用ADO.Net.
c# ×9
linq ×3
.net ×2
ado ×1
automapper ×1
c#-4.0 ×1
count ×1
expression ×1
lambda ×1
vb.net ×1