c# - 将类设为私有,因此值不会被修改
问题描述
我希望将 tile 类设为私有;特别是它不应该能够在构建后更改图块的值。
using System;
using System.Collections.Generic;
using System.Text;
namespace Tiles
{
class tile
{
readonly int[,] arr;//added this
public int [,] Print2DArray(int n)
{
int[,] arr;
do
{
Random random = new Random();
arr= new int[n, n];
int k = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
arr[i, j] = k++;
}
}
这returns
对于主程序,磁贴和主程序是单独的 .cs 文件我将如何制作它,以便返回后的值不会被修改。
主要的:
Tile mytiles = new Tile();
int[,] original = mytiles.Print2DArray(n);
解决方案
推荐阅读
- mysql - 在 Vue.JS 中使用 aws Mysql 使用 SQL
- bmc - 如何在 BMC 中本地化目录项名称?
- javascript - 如何在不和谐的通话中让每个人都静音(指定频道)
- javascript - 为什么一个异步函数在一个承诺稍后开始之后才完成执行?
- r - 使用 Akaike 信息准则 (AIC) 和贝叶斯信息准则 (BIC) 过滤 mlr3 中的 PCA 因子?
- tensorflow - Colab 标准 CPU、GPU 性能测试错误:TF 1 GPU vs CPU bad performance 1x
- azure-active-directory - 使用自定义策略从 Azure AD B2C 撤消访问权限
- css - 在 CSS 样式中使用“>>>”选择器是什么意思?
- charts - 如何更改工具提示的位置
- android-studio - 带有 Ubuntu 的 Android Studio 上的超大 Android 模拟器