小编Gra*_*ICA的帖子

控件不能从一个案例标签跌落到另一个案例

我环顾四周,我已经知道这意味着中断是无法到达的,但是我不知道它是如何无法到达的或者它试图达到什么目的。我收到错误的代码如下,也许有人可以告诉我添加哪些内容以使中断可到达:

#region :buy <item>

case "buy":
    string Item = stringManager.wrapParameters(args, 1);

    if (Item == "bread") 
    {
        int foodfunds;
        int myfood;
        int foodCheck;
        int creditCheck;
        using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
            foodfunds = dbClient.getInt("SELECT credits FROM users WHERE name = '" + _Username + "'");
        using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
            myfood = dbClient.getInt("SELECT food FROM users WHERE name = '" + _Username + "'");
        if (foodfunds < 10)
        {
            Room.sendData("BK" + "Not enough cash.");
        }
        if (_roomID != 193)
        {
            sendData("BK" + …
Run Code Online (Sandbox Code Playgroud)

c# sql

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

C#int.TryParse也许?

所以这是我一直想弄清楚但似乎无法解决的错误..这是一个功能.

File.Copy(item.FileName, mcAD [VersionText.Tag], true);

private void Version_2_0_Click(object sender, EventArgs e)
{
    string Version_2_0_Selected = VersionText.Text = "Version 2.0";
    VersionText.Tag = 2;
}
Run Code Online (Sandbox Code Playgroud)

VersionText.Tag在第一部分总是给我这个错误.

在此输入图像描述

我听说过int.TryParse,但我无法弄清楚如何在我的代码中实现它.

我希望我解释得足够多.

c# if-statement

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

在Visual Studio中将GUI添加到现有代码

我在Visual Studio 2010中使用C#构建了一个应用程序,并且它已成功运行.假设代码文件名是program.cs

我想为应用程序构建一个简单的GUI,因此它比命令提示符更加用户友好.

最初,应用程序将在命令提示符中请求用户输入.我的目标是允许用户使用ComboBoxTextBox提供输入并点击执行按钮来启动程序.

我尝试了添加新项> Windows窗体,但是当我点击F5时,程序仍然在命令提示符下运行,看起来它只是忽略我刚刚创建的表单.当我注释掉整个program.cs文件并运行时,我得到一个错误,说没有" Main() "

我的问题是:实现目标的最佳/最简单方法什么?为了将表单链接到现有代码,我需要在代码中进行哪些更改?

另一个注意事项:目前用户可以将可执行文件运行到任何地方.完成上述目标后,我希望用户能够获取表单并在任何地方运行它.(我不确定可执行文件是否会运行表单而不是命令提示符,或者别的.我对此不太熟悉)

c# visual-studio-2010 winforms

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

什么.*在正则表达式中做什么?

经过广泛搜索后,我无法在正则表达式中找到需要使用.*的解释.例如,MSDN建议使用密码正则表达式

@\"(?=.{6,})(?=(.*\d){1,})(?=(.*\W){1,})"
Run Code Online (Sandbox Code Playgroud)

长度> = 6,1 +数字和1+特殊字符.

为什么我不能使用:

@\"(?=.{6,})(?=(\d){1,})(?=(\W){1,})"
Run Code Online (Sandbox Code Playgroud)

c# regex

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

未知的C#错误

嗨,我不知道为什么C#在我的最后一个Curly Bracket上有一个解析错误,对不起,如果它很简单,我很新C#这里是代码.

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour
{
    public string IP = "192.168.0.8";
    public int Port = "25001";

    void OnGUI()
    {
        if(Network.peerType == NetworkPeerType.Disconnected)
        {
            if (GUI.Button(new Rect(100,100,100,25),"Join Existing Server"))
            {
                Network.Connect(Ip,Port);    
            }

            if (GUI.Button(new Rect(100,125,100,25),"Create New Server"))
            {
                Network.InitializeServer(10,Port);
                //First Number Above next to port in perenthisies is number of allowed clients / 1x Server (# of players allowed to join game.)
            }
            else 
            {
                if(Network.peerType == NetworkPeerType.Client)    
                {
                    GUI.Label(new Rect(100,100,100,25),"Client");
                    if(GUI.Button (new Rect(100,125,100,25),"Disconnect"))
                    { …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

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

在查询Linq中列出变量

我创建了一个变量,它返回数据库中菜单的列表ID.然后我将变量放在另一个返回列表中的菜单的查询中.我的问题是,我一直recieving误差不能隐式类型转换System.Collections.Generic.List<int?>int?

var getmenuids = (from r in db.Menus
                  where (r.Restaurantid == currentrestaurant)
                  select r.Id).ToList();

var meals = db.Meals.Where(r => r.MenuID = getmenuids).ToList();
Run Code Online (Sandbox Code Playgroud)

c# linq asp.net

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

继承缺少定义

我正在写一个简单的程序来理解继承.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    public enum AnimalType
    {
        Dog = 0,
        Cat = 1
    }

    class Program
    {
        static void Main(string[] args)
        {
            Dog dog = new Dog();

            dog.printAnimal();
        }
    }

    class Animal
    {
        public string AnimalName;
        public AnimalType AnimalType;

        public Animal()
        {
            SetAnimalName ("");
            SetAnimalType (AnimalType.Dog);
        }

        public Animal (string animalName, AnimalType animalType)
        {
            SetAnimalName (animalName);
            SetAnimalType (animalType);
        }

        public virtual void PrintAnimal ()
        {
            Console.WriteLine("Animal::PrintAnimal -> this function …
Run Code Online (Sandbox Code Playgroud)

c# visual-studio-2013

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

多维数组中所有数字的总和

我正在学习C#并遇到多维数组的问题.

我似乎无法弄清楚如何找到数组中所有元素的总和.例如

int[,] array = { { 52, 76, 65 }, { 98, 87, 93 }, { 43, 77, 62 }, { 72, 73, 74 } };
Run Code Online (Sandbox Code Playgroud)

所以总和应该是:

52 + 76 + 65 + 98 + ......

我试图使用for循环,但这只是给我维度1中每个数组的总和.例如

private int[,] array = { { 52, 76, 33}, { 98, 87, 93 }, { 43, 77, 62 }, { 72, 73, 74 } };
public void ArraySum()
{      
    double sum;        
    for (int i = 0; i < array.GetLength(0); i++)
    {
        sum …
Run Code Online (Sandbox Code Playgroud)

c# multidimensional-array

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

在ForEach语句中使用linq

我正在尝试使用Linq和我的ForEach语句来显示组中的输出.

我的代码看起来像这样:

Rooms.ToList()
     .ForEach(room => room.RoomContents.ToList()
         .ForEach(roomContents => roomContents.SupportedCommands.ToList()
             .ForEach(command => Console.Write("\nThe commands for {0} are: {1} ", roomContents.Name, command))));          

Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

电流输出:

The command for Tap are Use
The command for Key are Drop
The command for Key are Get
The command for Key are Use
The command for Bucket are Drop
The command for Bucket are Get
The command for Bucket are Use
Run Code Online (Sandbox Code Playgroud)

我的目标是以更友好的方式显示输出,即根据房间内容对命令进行分组.我希望输出显示这样的东西.

期望的输出:

The commands for Tap 
Use
The commands for Key 
Drop
Get
Use …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

如何从BackgroundWorker线程中更新标签?

当我使用WinForms时,我会在我的bg_DoWork方法中完成这个:

status.Invoke(new Action(() => { status.Content = e.ToString(); }));
status.Invoke(new Action(() => { status.Refresh(); }));
Run Code Online (Sandbox Code Playgroud)

但是在我的WPF应用程序中,我得到一个错误,Invoke说不存在Label.

任何帮助,将不胜感激.

c# wpf xaml backgroundworker

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