C# 在Color[] colorTable中快速找到Color的索引位置
作者:野牛程序员:2023-12-25 12:43:48C#阅读 2848
可以使用Array.IndexOf方法来在Color[] colorTable中查找特定的Color对象,并返回其索引位置。以下是一个简单的示例代码:
using System;
using System.Drawing;
class Program
{
static void Main()
{
// 假设有一个Color数组
Color[] colorTable = { Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Orange };
// 要查找的Color对象
Color targetColor = Color.Blue;
// 使用Array.IndexOf方法查找Color对象的索引位置
int index = Array.IndexOf(colorTable, targetColor);
// 输出结果
Console.WriteLine($"目标颜色 {targetColor} 的索引位置是: {index}");
}
}在这个例子中,定义了一个Color数组colorTable,并使用Array.IndexOf方法查找targetColor在数组中的索引位置。
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892

- 上一篇:C++ 矩形图像旋转后的宽高计算方法
- 下一篇:C++ 写入txt文件内容并追加内容
