mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-31 18:39:00 +08:00
feat(extensions): 添加数组扩展方法支持二维数组边界检查
- 实现 IsInBounds 扩展方法用于检查二维数组坐标边界 - 提供泛型支持以适配不同类型的二维数组 - 包含完整的 XML 文档注释说明方法用途和参数 - 遵循 Apache 2.0 开源协议规范添加版权头文件
This commit is contained in:
parent
76a1406346
commit
6908c74efc
35
GFramework.Core/Extensions/ArrayExtensions.cs
Normal file
35
GFramework.Core/Extensions/ArrayExtensions.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (c) 2026 GeWuYou
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
namespace GFramework.Core.Extensions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数组扩展方法类,提供二维数组的边界检查等实用功能。
|
||||||
|
/// </summary>
|
||||||
|
public static class ArrayExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 检查二维数组的给定坐标是否在有效边界内。
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">数组元素类型。</typeparam>
|
||||||
|
/// <param name="array">要检查的二维数组。</param>
|
||||||
|
/// <param name="x">要检查的 X 坐标(第一维索引)。</param>
|
||||||
|
/// <param name="y">要检查的 Y 坐标(第二维索引)。</param>
|
||||||
|
/// <returns>如果坐标在数组边界内则返回 true;否则返回 false。</returns>
|
||||||
|
public static bool IsInBounds<T>(this T[,] array, int x, int y)
|
||||||
|
{
|
||||||
|
return x >= 0 && y >= 0 &&
|
||||||
|
x < array.GetLength(0) &&
|
||||||
|
y < array.GetLength(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user