почему я получаю ошибку System.IndexOutOfRangeException: 'Index has to be between upper…
- User
почему я получаю ошибку System.IndexOutOfRangeException: 'Index has to be between upper and lower bound of the array.' в своей программе при выполнении этой команды? private void StartNewGame() { _game = new Game(fieldSize); OnPropertyChanged(nameof(Turn)); OnPropertyChanged(nameof(board));
}вот мои файлы: 1)
<ContentPage.BindingContext> <vm:ViewM/> </ContentPage.BindingContext> <AbsoluteLayout> <Frame BackgroundColor="#2196F3" Padding="12" CornerRadius="0" AbsoluteLayout.LayoutBounds="0, 0, 1, 0.14" AbsoluteLayout.LayoutFlags="All" > <Label Text="TicTacToe" TextColor="White" FontSize="36" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" /> </Frame> <Grid HorizontalOptions="Center" AbsoluteLayout.LayoutBounds="0.5, 0.15" AbsoluteLayout.LayoutFlags="PositionProportional"> <Label Text="X:" FontSize="36" Grid.Column="0" HorizontalTextAlignment="Center"/> <Label Text="{Binding Xwins}" FontSize="36" Grid.Column="1" HorizontalTextAlignment="Center"/> <Label Text="O:" FontSize="36" Grid.Column="3" HorizontalTextAlignment="Center"/> <Label Text="{Binding Owins}" FontSize="36" Grid.Column="4" HorizontalTextAlignment="Center"/> </Grid> <Grid HorizontalOptions="Center" AbsoluteLayout.LayoutBounds="0.5, 0.23" AbsoluteLayout.LayoutFlags="PositionProportional"> <Label Text="Turn:" FontSize="36" Grid.Column="0" HorizontalTextAlignment="Center"/> <Label Text="{Binding Turn}" FontSize="36" Grid.Column="1" HorizontalTextAlignment="Center"/> </Grid> <Grid x:Name="field" AbsoluteLayout.LayoutBounds="0.5, 0.5, 1, 0.4" AbsoluteLayout.LayoutFlags="All"> </Grid> <Grid AbsoluteLayout.LayoutBounds="0.5, 0.9, 1, 0.1" AbsoluteLayout.LayoutFlags="All"> <Grid.ColumnDefinitions> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="2*" /> </Grid.ColumnDefinitions> <Button Text="-" Grid.Column="0" Command="{Binding MinusSize}"/> <Label Text="{Binding fieldSize}" FontSize="42" Grid.Column="1" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/> <Button Text="+" Grid.Column="2" Command="{Binding PlusSize}"/> </Grid> <Button Text="New game" FontSize="36" AbsoluteLayout.LayoutBounds="0.5, 1, 1, 0.1" AbsoluteLayout.LayoutFlags="All" Command="{Binding StartGame}" Clicked="ReDraw"/> </AbsoluteLayout>using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using Xamarin.Forms;
namespace TicTac { public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); InitializeGameField(); }
- Assistant
Чтобы разобраться с ошибкой
System.IndexOutOfRangeException, особенно в вашем игровом приложении для крестиков-ноликов, надо обратить внимание на несколько возможных причин и проблем:-
Инициализация массива : Вы правильно создаете массив в классе с размером . Это означает, что индексы этого массива будут в диапазоне от до .
-
- User
забыл добавить что эта ошибка возникает только при уменьшении поля
- Assistant