我有奇怪的行为,我在特定位置的代码没有步入特定方法。没有错误,什么也没有。它只是到达终点线,而没有踏入终点线。我正在调试并逐步执行每个步骤以发现该问题。我不知道发生了什么,这是我第一次遇到这样的问题。下面找到我的代码,最后解释了它发生的具体位置。
static class Program
{
private static UnityContainer container;
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Bootstrap();
Application.Run(container.Resolve<FrmLogin>());
}
private static void Bootstrap()
{
container = new UnityContainer();
container.RegisterType<IRepositoryDal<User>, UserRepositoryDal>();
container.RegisterType<IRepositoryDal<Order>, OrderRepositoryDal>();
container.RegisterType<IDbManager, DbManager>(new InjectionConstructor("sqlserver"));
container.RegisterType<IGenericBal<User>, UserBal>();
container.RegisterType<IGenericBal<Order>, OrderBal>();
}
}
public partial class FrmLogin : Form
{
private readonly IGenericBal<User> _userBal;
public FrmLogin(IGenericBal<User> userBal)
{
InitializeComponent();
_userBal = userBal;
}
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
var a = _userBal.SearchByName("John");
}
catch (Exception ex)
{ …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建通用查询以传递我想要依赖的列名和表名我要选择值.
到目前为止这是我的代码:
ALTER PROCEDURE [dbo].[GenericCountAll]
@TableName VARCHAR(100),
@ColunName VARCHAR(100)
AS
BEGIN
DECLARE @table VARCHAR(30);
DECLARE @Rowcount INT;
SET @table = N'SELECT COUNT(' + @ColunName +') FROM ' + @TableName + '';
EXEC(@table)
SET @Rowcount = @@ROWCOUNT
SELECT @Rowcount
END
Run Code Online (Sandbox Code Playgroud)
试图像这样执行:
EXEC GenericCountAll 'T_User', 'Id';
Run Code Online (Sandbox Code Playgroud)
但看起来我得到两个结果,第一个结果总是返回值1,第二个结果返回实际计数.有人可以看看吗?
我有两个变量CarsSelected和PlanesSelected. 如果有人设置了其中一个,我希望将另一个变量设置为相反的值,因此如果一个为真,另一个必须为假,反之亦然。因此,两个变量最终总是不同的。我的问题是我的代码infinite loop在更改任何值时进入。如何解决?
public class MyClass
{
private bool _carsSelected;
private bool _planesSelected;
public bool CarsSelected
{
get => _carsSelected;
set
{
_carsSelected= value;
PlanesSelected= !_carsSelected;
}
}
public bool PlanesSelected
{
get => _planesSelected;
set
{
_planesSelected= value;
CarsSelected= !_planesSelected;
}
}
public MyClass()
{
CarsSelected= false;
PlanesSelected= false;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个问题,如果在所有可能的Dog实例上共享静态方法Do,为什么我的其他实例无法使用Do方法更改内部值或者看到所有实例的值都相同?
class Program
{
static void Main(string[] args)
{
Console.WriteLine("First value: " + Dog.Do(0));
Console.WriteLine("After first change: " + Dog.Do(5));
Dog dog1 = new Dog();
Dog dog2 = new Dog();
//cant use why ? i want to see from other instances of Dog about value either k is same for all instances
//dog1.Do(44);
//Console.Writeline(dog2.Do(0));
Console.ReadLine();
}
public class Dog
{
public static int Do(int t)
{
int k = 3;
k = k + t;
return k;
}
public int …Run Code Online (Sandbox Code Playgroud)