热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在C#中开发MP3播放器时,如何选择字典或数组来处理元数据?

在C#中开发MP3播放器时,我正在考虑如何高效存储元数据以便快速检索。选择合适的数据结构,如字典或数组,对于优化性能至关重要。字典能够提供快速的键值对查找,而数组则在连续存储和遍历方面表现优异。根据具体需求,合理选择数据结构将显著提升应用的响应速度和用户体验。

i'm writing an mp3 player in c#, and i'm wondering how to store the metadata for quick retrieval. here's the data i need to store for each individual file:

我正在用c#编写一个mp3播放器,我想知道如何存储元数据以便快速检索。这是我需要为每个文件存储的数据:

  • file location
  • file name
  • artist
  • album
  • track title
  • album artwork

how should i store the data? dictionary of arrays? dictionary of dictionaries? i want to populate a listbox with individual entries, so if i have a button that says artist, it will quickly get the artist info, put it in an array and populate the listbox.

我该如何存储数据?数组字典?词典词典?我想填充一个包含单个条目的列表框,所以如果我有一个说艺术家的按钮,它将快速获取艺术家信息,将其放入数组并填充列表框。

3 个解决方案

#1


2  

How about a generic list?

通用列表怎么样?

// define song object.
public class Song 
{
    public string FileLocation { get; set; }
    public string FileName { get; set; }
    public string Artist { get; set; }
    public string Album { get; set; }
    public string TrackTitle { get; set; }
    public string AlbumArtwork { get; set; }
}

// create list of songs.
List sOngs= new List();

// add new song to list.
songs.Add(new Song {
        FileLocation = "/filepath/sade.mp3",
        FileName = "Sade", 
        Artist = "Sade", 
        Album = "Sade", 
        TrackTitle = "Smooth Operator", 
        AlbumArtwork "TBD"
});

// access first song in list.
Song sOng= songs[0];

// access property of song.
string trackTitle = song.TrackTitle;

Of course you could break this down into an even more object-oriented design by making the song properties complex objects as well. For example:

当然,通过使歌曲属性也成为复杂的对象,你可以将其分解为更加面向对象的设计。例如:

public class Album
{
    public string Name
    public DateTime ReleaseDate
    public string Artwork { get; set; }
}

public class Artist
{
    public string Name
    public List Albums
}

public class Song 
{
    public string FileLocation { get; set; }
    public string FileName { get; set; }
    public Artist Artist { get; set; }
    public string TrackTitle { get; set; }
}

And then, for example, access the album properties like this:

然后,例如,访问相册属性,如下所示:

string firstAlbumName = song.Artist.Albums[0].Name;

#2


1  

There doesn't seem to be anything there that would influence storage, do I would say "a list of classes", i.e. a List or similar, with

似乎没有什么会影响存储,我会说“类列表”,即List 或类似的,与

public class Track {
    public string Path {get;set;}
    ...
    public string Title {get;set;}
    public string ArtworkPath {get;set;}
}

If the volume is high, you might want to look at databases rather than in-memory storage. SQL Server (Express or Compact) for example, are both free. This may allow for more specialised indexing without much effort, plus pre-built persistence.

如果卷很高,您可能需要查看数据库而不是内存存储。例如,SQL Server(Express或Compact)都是免费的。这可以允许更加专业化的索引而不需要太多努力,以及预先构建的持久性。

#3


1  

The best way to store your data is in a database, there are different types a small free database to choose from. For example sqlite is nice. You can use sql for fast access of of the data (searching, grouping, etc).

存储数据的最佳方式是在数据库中,有不同类型的小型免费数据库可供选择。例如sqlite很好。您可以使用sql快速访问数据(搜索,分组等)。


推荐阅读
author-avatar
The-6ixth-Floor乐队
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有