Creating dynamic variable names in C#

前端 未结 4 1357
北海茫月
北海茫月 2020-12-17 03:25

I am trying to write a simple role playing game in C# to become more familiar with the language.

I have a class that loads data from CSV file, creates an object, and

4条回答
  •  时光取名叫无心
    2020-12-17 04:15

    Why not create a manager object responsible for reading data and returning instances of specified objects? Something like:

    var actors = ActorsLoader.Load("actors.cvs");
    

    where ActorsLoader.Load could be implemented as:

    IEnumerable Load( string fileName )
    {
        //1. reading each line (each line = new actor) & creating actor object
        //2. adding created actor object to a collection
        //3. returning back a collection
    }
    

    I have assumed that each type of in-game objects are stored in separate files (so that you have: actors.csv, items.csv, skills.csv etc.)

提交回复
热议问题