我知道这个问题是什么,但我对我的程序如何输出一个超出数组的值感到困惑.
我有一个0到8的整数,这意味着它可以保持9个整数,对吗?我有一个int,检查以确保用户输入值是1-9.我从整数中删除一个(像这样)
if (posStatus[intUsersInput-1] == 0) //if pos is empty
{
posStatus[intUsersInput-1] += 1;
}//set it to 1
Run Code Online (Sandbox Code Playgroud)
然后我自己输入9并得到错误.它应该访问数组中的最后一个int,所以我不明白为什么我会收到错误.相关代码:
public int[] posStatus;
public UsersInput()
{
this.posStatus = new int[8];
}
int intUsersInput = 0; //this gets try parsed + validated that it's 1-9
if (posStatus[intUsersInput-1] == 0) //if i input 9 it should go to 8?
{
posStatus[intUsersInput-1] += 1; //set it to 1
}
Run Code Online (Sandbox Code Playgroud)
错误:
"Index was outside the bounds of the array." "Index was outside the bounds of …Run Code Online (Sandbox Code Playgroud) 所以基本上我遇到了我已经给出的任务的问题.我不会厌倦任务本身的细节,所以我只会给你相关的信息.
我有一本字典,我需要按最高的int [value]排序,准确地排在前五位,我需要能够显示底部的五位.
Dictionary<string, int> dict = new Dictionary<string, int>();
Run Code Online (Sandbox Code Playgroud)
字符串(键)包含已为文本文件读取的单词.整数(值)包含文档中提到它们的次数.
我打算用另一种方式做,但我被告知要用字典做,所以请字典只帮助.我很感激,如果你能解释它应该怎么做,这样我就可以学习并完成任务,因为任务的目的是教育自己,但我发现它有点难...
我提前感谢您的帮助,如果需要更多信息,请告诉我,我会发布!
我有一个屏幕,用户可以在其中选择一个选项(不是浏览图库,因为它不会执行所需的操作).
我想将用户选择的项目传递给浏览库使用的预制"DetailScreen1".
我查看了浏览屏幕,但没有看到它是如何做的,因为导航onselect事件只是正常导航.
码:
Navigate(DetailScreen1, ScreenTransition.Fade)
Run Code Online (Sandbox Code Playgroud)
我想做点什么
Navigate(DetailScreen1, ScreenTransition.None {Last(listOfStuff)})
Run Code Online (Sandbox Code Playgroud)
谢谢
我已经编写了代码来检查 CRM 中的记录是否存在。问题是当没有找到记录时 IOrganisationService.Retrieve 返回错误而不是空值。我希望找不到多条记录,我不想使用 try catch 然后使用 catch 中的错误。
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, credentials, null))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
//Get record
var record = service.Retrieve(entryId, guid, new ColumnSet(true)); //switch to var if no work
//Check if record is not null/empty
recordExists = !String.IsNullOrWhiteSpace(record.Id.ToString()); //<- does the record exist
}
Run Code Online (Sandbox Code Playgroud)
建议?
我的错误:
Field 'StockManagement.LargeItems1.largeS' is never assigned to, and will always have its default value null
我的代码:
namespace StockManagement
{
class LargeItems1
{
private Stack<string> largeS;
public LargeItems1()
{
Stack<string> largeS = new Stack<string>();
}
public void LargeItemsAdd()
{
string usersInput2, tempValue;
int tempValueI = 0;
bool attempt = false;//, whichOne = false;
Console.WriteLine("Would you like to remove or add an item to the storage area \n Reply add OR remove");
string usersInput = Console.ReadLine();
usersInput = usersInput.ToLower();
if (usersInput.Contains("remove"))
{ …Run Code Online (Sandbox Code Playgroud) 我对linq online的解释感到有些困惑,所以我想我会创建一个帖子.
我想用linq语句替换我的foreach语句,因为我确信做这样的小事会让我的程序更好.
我想用LINQ做的例子:
public bool CheckForAccount(int accountID)
{
bool status = false;
foreach (AccountHolders accountHolder in AccountHoldersList)
{
if (accountHolder.AccountNumber == accountID)
{
status = true;
break;
}
}
return status;
}
Run Code Online (Sandbox Code Playgroud)
请你能解释它是如何工作的,所以我理解你在做什么.
提前致谢!
我有一个字符串,用于我的程序从中读取数据的文件的路径.我想提高稳健性,我记得看到有人这样做.\ blabla\blalbla \但我发现有点难以找到解释这项工作的主题,所以我可以将它实现到我的程序中.
我的路径(我知道命名不正确,但如果我用大写字母P命名它会干扰我的属性)
private const string path = @"C:\Users\zain\Desktop\program_storage\AccountDatabase.txt";
Run Code Online (Sandbox Code Playgroud)
我希望它会像.\program_storage\AccountDatabase.txt(不幸的是这不起作用),因为它意味着我可以移动程序而不必更改常量类中的字符串.
任何和所有的帮助表示赞赏
我想从表中删除一些数据.我想删除内部联接中未包含的数据
我的查询到目前为止:
DELETE *how do you say delete what wasn't included in the inner join?*
from dbo.Cloudpie c
inner join dbo.cake p
on c.cakeid = p.cakeid
where cakeid > 1
Run Code Online (Sandbox Code Playgroud)
在此先感谢所有提供的任何帮助:)!
所以,我有一张卡片.这个类构造函数如下:
public Cards(int data, string typeIEking, string suitIEspades)
{
valueOfCard = data;
specialCards = typeIEking;
suit = suitIEspades;
}
public Cards(int data, string suitIEspades)
{
valueOfCard = data;
specialCards = null;
suit = suitIEspades;
}
Run Code Online (Sandbox Code Playgroud)
我之前已将数据放入此卡但现在我想显示数据(在构造函数中命名为valueOfCard),适合并且如果它是特殊卡(即国王).
所以我将这张卡传递给另一种方法,但现在我想在结果中显示数据,但是当我输入cardName时,出现的唯一选项是Equals,GetHashCode和ToString.
我很困惑为什么会这样,我不知道如何解决它.我想象我会做的nameOfCard.valueOfCard;
我想让用户在用户可以做某事之前等待5秒但是我遇到了麻烦,因为我不想这样做,Thread.Sleep(5000);因为我希望加载表单并且功能可以查看但是我没有想要允许用户为这5秒做任何事情(他们可以尝试点击按钮,但不会发生任何事情).
由于回答者,我做了这项工作(由于属性,我的代码略有不同):
var t = Task.Delay(1000) //1 second/1000 ms
t.Wait();
Run Code Online (Sandbox Code Playgroud) 我似乎无法想象如何使用元素功能弹出堆栈的项目.有人可以告诉我该怎么做?
相关代码:
Stack<Cards> stackOfCards = new Stack<Cards>();
Run Code Online (Sandbox Code Playgroud)
我以前把物品放进这个堆栈.
Random random = new Random();
int randomNumber = random.Next(0, 52);
for (int i = 0; i < 200; i++)
{
stackOfCards.ElementAt(randomNumber);//how do i pop this?
}
Run Code Online (Sandbox Code Playgroud)
PS Do堆栈从0还是1开始?那么对于一副牌是0-51还是1-52?
我想重构一个方法,但我不太清楚如何,但我知道你可以做到.
我目前的方法:
public bool AdminShutdown(int accountID, int accountPin)
{
var status = false;
if (accountID == AdminLogin && accountPin == AdminPin)
{
status = true;
}
return status;
}
Run Code Online (Sandbox Code Playgroud)
我认为它应该是类似
var status = (accountID == AdminLogin) && (accountPin == AdminPin)但不起作用( Operator '&&' cannot be applied to operands of type 'bool' and 'int').
建议?
PS这段代码有用吗?
var tempReturnPerson = AccountHoldersList.Single((x => x.AccountNumber == accountId));
Run Code Online (Sandbox Code Playgroud)
代替:
public AccountHolders ReturnAccountInfo(int accountId)
{
//use linq to do this later
var returnPerson = new …Run Code Online (Sandbox Code Playgroud)