通过索引器进行照片的添加和查询
设计界面:

编写代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections; //引入命名空间
namespace 索引器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
Album a = new Album(3);
//添加照片
private void button2_Click(object sender, EventArgs e)
{
int i = Convert.ToInt32(textBox2 .Text)-1;
Photo p = new Photo(textBox1 .Text);
a[i] = p;
label3.Text = string.Format("照片添加成功!");

本文介绍如何在C#中使用索引器实现照片的添加、查询和显示。通过创建相册类和照片类,利用索引器进行照片的存取操作,包括按位置索引和按标题搜索。
最低0.47元/天 解锁文章
200

被折叠的 条评论
为什么被折叠?



