Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 558875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:10:40+00:00 2026-05-13T12:10:40+00:00

I am relatively new to C#, having done most of my previous programming in

  • 0

I am relatively new to C#, having done most of my previous programming in VB6. I know C# is much more explicitly typed than VB, but I’m hoping that there is a solution for my problem.

I am working on a project that is designed to open, parse, validate, and eventually edit 5 different CSV files that are used as input to an application we use. Manually manipulation of the CSV files is what is done now, but it is difficult for most users because of lack of documentation and support from the original developer. My goal is to build a GUI that will permit users to directly edit the fields and create a new CSV file to use as an import. Here’s the basic structure now:

public class Dataset
{
    public Dictionary<string,File1> file1 = new Dictionary<string,File1>();
    public Dictionary<string,File2> file2 = new Dictionary<string,File2>();
    public Dictionary<string,File3> file3 = new Dictionary<string,File3>();
    public Dictionary<string,File4> file4 = new Dictionary<string,File4>();
    public Dictionary<string,File5> file5 = new Dictionary<string,File5>();

    public void SelectFiles()
    {
        //User specifies which file(s) are to be opened (default is all 5 files)
    }

    public class File1
    {
        public string Field_1 {get ; set}
        public string Field_2 {get ; set}
        .
        .
        .
        public string Field_10 {get ; set}
    }
    public class File2
    {
        public string Field_1 {get ; set}
        public string Field_2 {get ; set}
        .
        .
        .
        public string Field_31 {get ; set}
    }
    public class File3
    {
        public string Field_1 {get ; set}
        public string Field_2 {get ; set}
        .
        .
        .
        public string Field_57 {get ; set}
    }
    public class File4
    {
        public string Field_1 {get ; set}
        public string Field_2 {get ; set}
        .
        .
        .
        public string Field_68 {get ; set}
    }
    public class File5
    {
        public string Field_1 {get ; set}
        public string Field_2 {get ; set}
        .
        .
        .
        public string Field_161 {get ; set}
    }
}

The challenge is reading the data from the CSV into each of the dictionaries. Right now that is accomplished with 5 different functions (actually one function overloaded 5 times)

public Dictionary<string,File1>ReadFile(string file)
{
    //Open and Parse File #1, and store in File1 class and accessed by file1 dictionary
}
public Dictionary<string,File2>ReadFile(string file)
{
    //Open and Parse File #2, and store in File2 class and accessed by file2 dictionary
}
public Dictionary<string,File3>ReadFile(string file)
{
    //Open and Parse File #3, and store in File3 class and accessed by file3 dictionary
}
public Dictionary<string,File4>ReadFile(string file)
{
    //Open and Parse File #4, and store in File4 class and accessed by file4 dictionary
}
public Dictionary<string,File5>ReadFile(string file)
{
    //Open and Parse File #5, and store in File5 class and accessed by file5 dictionary
}

The code for opening and parsing the CSV file is all virtually identical, differing only by the Type for the dictionary. So when I make a change to this function, I have to make sure I make identical changes to the other 4 functions, and I’m worried that it will make maintaining the code in the future more of a problem. Is there any possible way I can create a single function with no overloads where I can pass the type as a parameter to the function?

public Dictionary<string,[UnknownType]>ReadFile(string file, [UnknownType] typ)
{
    //Open and Parse File and read into class specified by typ
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:10:41+00:00Added an answer on May 13, 2026 at 12:10 pm

    Object Orientation my Friend. Coming from a VB6-perspective that might not be what you are use to. But instead of having File1 -> File5, why don’t you have a “CVSFile”-object which you then, if you really must, derive from. Which would help you in Many ways.

    Polymorphism

    Check out MSDN on how to use Polymorphism in C#

    Snippet from MSDN:

    public class BaseClass
    {
        public void DoWork() { }
        public int WorkField;
        public int WorkProperty
        {
            get { return 0; }
        }
    }
    
    public class DerivedClass : BaseClass
    {
        public new void DoWork() { }
        public new int WorkField;
        public new int WorkProperty
        {
            get { return 0; }
        }
    }
    
    DerivedClass B = new DerivedClass();
    B.DoWork();  // Calls the new method.
    
    BaseClass A = (BaseClass)B;
    A.DoWork();  // Calls the old method.
    

    Edit

    Just to clearify a bit

    When the new keyword is used, the new
    class members are called instead of
    the base class members that have been
    replaced. Those base class members are
    called hidden members. Hidden class
    members can still be called if an
    instance of the derived class is cast
    to an instance of the base class.

    And if you like to use virtual methods instead:

    In order for an instance of a derived
    class to completely take over a class
    member from a base class, the base
    class has to declare that member as
    virtual. This is accomplished by
    adding the virtual keyword before the
    return type of the member. A derived
    class then has the option of using the
    override keyword, instead of new, to
    replace the base class implementation
    with its own.

    public class BaseClass
    {
        public virtual void DoWork() { }
        public virtual int WorkProperty
        {
            get { return 0; }
        }
    }
    public class DerivedClass : BaseClass
    {
        public override void DoWork() { }
        public override int WorkProperty
        {
            get { return 0; }
        }
    }
    

    In this case the result will be this

    DerivedClass B = new DerivedClass();
    B.DoWork();  // Calls the new method.
    
    BaseClass A = (BaseClass)B;
    A.DoWork();  // Also calls the new method.
    

    All examples are take from MSDN

    How to apply this on your example

    Let’s say that you have a LoadCSV-method, instead of having 5 different methods that returns each object, you can easily just say “Hey I will return a CVSFile, don’t you care about anything else!”.

    There are a lot of good turorials out there, and the “Programming for kids” have the Best illustrations on the fundamentals. Check this out: Object Orientation For Kids ( No offense. )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still relatively new to C++ and programming, but having a good time learning.
I'm a relatively new Java programmer and I'm having difficuly removing more than one
I'm relatively new to Android programming, and am having a problem with inflation. I'm
I'm relatively new to MongoDB and having trouble with a more advanced upsert. I've
I'm relatively new to Python and am having problems programming with Scapy, the Python
I am relatively new to C programming and having a hard time understanding the
I'm relatively new to Oracle, having working on MS SQL for most of my
I am relatively new to C++ and am having problems understanding struct. I have
I 'm relatively new to git and and having some problems early on. I've
Relatively new to WinForms but I'm working on a small business app. Anyway, where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.