Avatar of ukerandi
ukerandi
Flag for United Kingdom of Great Britain and Northern Ireland asked on

C# Class issue

Hi see code below, i like to know this is write way to do that. code is working fine, but i feel something is not right.

My purpose is this code is  - in the text file has 3 lines, i need to access this 3 file  one by one.and need to put 3 variables.

see below code
string line = string.Empty;
Class ClientFiles
{

public  List<string []>  ClientSaveFileDetails()
{
List<string []> clientFileList = new List<string []>();
SaveFilename=@"C:\test.txt";
   using (StreamReader clientRead = new StreamReader(SaveFilename))
            {
                while ((line = clientRead.ReadLine()) != null)
                {
                    clientFileList.Add(new string[] { line });
                }
            }

            return clientFileList;
}



}


I have already called the above class using below code

ClientFiles cl=new ClientFiles();
List<string[]> clSitename = cl.ClientSaveFileDetails();


string rowdetail1=clSitename[0][0];//1st line of the file
string rowdetail2=clSitename[1][0];//2st line of the file
string rowdetail3=clSitename[2][0];//3st line of the file


Console.writeline(rowdetail1);

Console.writeline(rowdetail2);


Console.writeline(rowdetail3);

Open in new window


can some one show me its not right way? if yes please show me what is the best way to do that.thx
C#.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
Miguel Oz

8/22/2022 - Mon
SOLUTION
Michael Fowler

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Miguel Oz

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61