小编dca*_*tro的帖子

指定的演员表无效

有人可以帮我这个...我只是无法找到错误的位置...因为即使我输入正确的用户名和密码弹出一条消息说指定的演员无效

if (user_txt.Text != "" & pass_txt.Text != "")
{
    string queryText = "SELECT Count(*) FROM stiguidancesample.users " + "WHERE username = @Username AND password = @Password";
    MySqlConnection cn = new MySqlConnection(MyConnectionString);
    MySqlCommand cmd = new MySqlCommand(queryText, cn);
    {
        cn.Open();
        cmd.Parameters.AddWithValue("@Username", user_txt.Text);  // cmd is SqlCommand 
        cmd.Parameters.AddWithValue("@Password", pass_txt.Text);
        int result = (int)cmd.ExecuteScalar();
        if (result > 0)
            MessageBox.Show("Loggen In!");
        else
            MessageBox.Show("User Not Found!");
    }
}
Run Code Online (Sandbox Code Playgroud)

c#

1
推荐指数
1
解决办法
3870
查看次数

把相框锁在角落里?

即使我调整窗体窗口的大小,如何才能使图片框始终锁定在 winforms 应用程序的右上角?

我尝试这样做:

pictureBox1.Margin = new Padding(5,5,0,0);
Run Code Online (Sandbox Code Playgroud)

但这没有用。我希望它始终从顶部填充 5 个,从右侧填充 5 个。无论表单窗口的大小是多少。

c# padding picturebox winforms

1
推荐指数
1
解决办法
1466
查看次数

每当我声明枚举时,它都不会编译

每当我声明一个enum,它就不会编译.我的代码看起来像这样:

private enum race {HUMAN, ORC, GOBLIN, UNDEAD}

// The name of the player
string playerName;

// The Health Points of the player. Is to be modified  a LOT. Keep that in mind!
int HP = 100;

// Made to test if the name chosen i the right one
bool nameIsRight = false;

cout("Hello fair traveler!\n\n");
cout("It has come to my knowledge, that you, a puny warrior, is up for the challenge, that is killing the dragon\n\n");

cout("Our …
Run Code Online (Sandbox Code Playgroud)

c# enums visual-studio-2012

1
推荐指数
1
解决办法
392
查看次数

使用智能指针的好处?

以此为例:

#include <memory>
#include <iostream>

int add(int a, int b) {
    return a+b;
}

std::unique_ptr<int> addp(int a, int b) {
    std::unique_ptr<int> ip(new int(a + b));
    return ip;
}

int main(int argc, char const* argv[])
{
    std::cout << add(3, 5) << std::endl;
    std::cout << *(addp(3, 5)) << std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

功能addp是否会提高性能,或者换句话说,是否可以避免复制数据?我怀疑结果a+b是在堆栈中,然后以任何方式复制到堆中.

c++ smart-pointers

1
推荐指数
2
解决办法
146
查看次数

“返回”和“返回新”之间的区别

当我阅读 C# 中的扩展方法时,我看到了下面的代码:

public static class ExtensionMethods
{
    public static string UpperCaseFirstLetter(this string value)
    {
        if (value.Length > 0)
        {
            char[] array = value.ToCharArray();
            array[0] = char.ToUpper(array[0]);
            return new string(array);
        }
        return value;
    }
}
class Program : B
{
    static void Main(string[] args)
    { 
        string value = "dot net";
        value = value.UpperCaseFirstLetter();
        Console.WriteLine(value);
        Console.ReadLine();
    }
}
Run Code Online (Sandbox Code Playgroud)

我评论了“返回新”礼物这一行并运行该程序。现在编译器读取代码“返回值”。如果我运行程序而不注释该行,则编译器不会读取“返回值”行。C# 中 return 和 return new 有什么区别?

c# asp.net

1
推荐指数
1
解决办法
481
查看次数

将Json反序列化为C#bool

我需要一个非常简单的问题的帮助.如何在不创建包装根对象的情况下将下面的json反序列化为C#bool.谢谢.

f
{"valid":false}
0
Run Code Online (Sandbox Code Playgroud)

c# json

1
推荐指数
1
解决办法
5103
查看次数

Scala中的不可变列表

我只想弄清楚像List这样的不可变的东西是如何工作的,以及我如何为它添加东西?

我很抱歉问这些愚蠢的问题,但是为什么我的列表在打印时总是空的?

var end = false
val list = List()
while (!end) {
  val input = scala.io.StdIn.readLine("input:")
  if (input == "stop" ) end = true
  else input :: list
}

println(list)

}
Run Code Online (Sandbox Code Playgroud)

很抱歉给我带来不便和这个相当愚蠢的问题!

scala list add immutability

1
推荐指数
1
解决办法
554
查看次数

处理完一个物体后会发生什么?

我有Label我的Form.当我调用Dispose()方法时,对象从中移除Form.但我仍然可以设置它的属性.在Dispose()为对象调用Method 之后会发生什么.我可以恢复它并再次显示它吗?

public void MyMethod()
{
     label1.Dispose();
     label1.Text = "Test";
     //No error happens
}
Run Code Online (Sandbox Code Playgroud)

在处理之后我可以读取一些属性,如Left属性.这意味着标签仍然存在于某个地方.我怎么能完全删除它?

c# dispose

0
推荐指数
1
解决办法
1537
查看次数

这是Liskov替换原则违规吗?

我的自定义按钮实际上是一个按钮,它是否违反了LSP?

class ConditionalButton : Button
{
    protected override void OnClick(EventArgs e)
    {
        if (Condition())
            base.OnClick(e);
    }
    private bool Condition()
    {
        //return true or false
    }
}
Run Code Online (Sandbox Code Playgroud)

c# oop solid-principles

0
推荐指数
1
解决办法
167
查看次数

C#中检测到"无法访问的代码"错误消息

我正在尝试用C#编写程序来查明数字是否为素数.我使用前两个if语句来挑出许多选项,然后我试图在最后的else语句中嵌套一个循环,它告诉我有"检测到无法访问的代码".

public static bool primeNumber ()
    {
        Console.Write ("Please enter a number to see if it is a prime number: ");
        int num = int.Parse (Console.ReadLine ());
        if (num % 2 == 0)
            return false;
        else if (num % 5 == 0)
            return false;
        else {
            for (int i = 3; i < num / 2; i += 2)
            {
                if (num % i == 0)
                    return false;
                else 
                    return true;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# if-statement unreachable-code

0
推荐指数
1
解决办法
5932
查看次数