• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

Concatenate in C#.

Hello everyone.

I have a very pertinent question.

My x.ini file has the following indices; 8760 if not leap year and 8784 for leap year:

csv_day_hour

csv_001_01=value
csv_001_02=value
csv_001_03=value
csv_001_04=value
...
I need to load these values into an string array.
I'm trying to populate the array with a for loop.

If use "Settings.csv.[" **.[**  the error message is this:  Identifier expected      
If use "Settings.csv[" **[**  the error message is this: Settings.csv' is a 'type', which is not valid in the given context

Any help please.
ocaccy

        private void getMonthHour()
            {
            if(File.Exists(ConfigINI))
                {
                IniFile ini=new IniFile(ConfigINI);
                
                #region Populate the array
                for(int d=1;d<=365;d++) //I'll put the code to not leap years.
                    {
                    for(int h=1;h<=24;h++)
                        {
                        if(d<10)
                            {
                            if(h<10) { sMntHour[d,h]=Settings.csv.["csv_00"+d.ToString()+"_0"+h.ToString()]; }
                            else { sMntHour[d,h]=Settings.csv.["csv_00"+d.ToString()+"_"+h.ToString()]; }
                            }

                        else if (d>10&&d<100)
                            {
                            if(h<10) { sMntHour[d,h]=Settings.csv.["csv_0"+d.ToString()+"_0"+h.ToString()]; }
                            else { sMntHour[d,h]=Settings.csv.["csv_0"+d.ToString()+"_"+h.ToString()]; }
                            }

                        else
                            {
                            if(h<10) { sMntHour[d,h]=Settings.csv.["csv_"+d.ToString()+"_0"+h.ToString()]; }
                            else { sMntHour[d,h]=Settings.csv.["csv_"+d.ToString()+"_"+h.ToString()]; }
                            }
                        }
                    }
                #endregion // Populate the array
                }
            }

Open in new window


error message
0
ocaccy
Asked:
ocaccy
  • 4
2 Solutions
 
Luis PérezSoftware Architect in .NetCommented:
You can try this:

for(int d=1;d<=365;d++) //I'll put the code to not leap years.
                    {
                    for(int h=1;h<=24;h++)
                        {
                             sMntHour[d,h]=Settings.csv.["csv_" + d.ToString("000") + "_" + h.ToString("00")];
                        }
                    }
                #endregion // Populate the array
                }

So you don't need to make an if because you can force the ToString function to return formatted days & hours.

Hope that helps.
0
 
ocaccyAuthor Commented:
Hi Luis,

This help me; bit has problem on concatenation.
0
 
ocaccyAuthor Commented:
Hi Luis, Thís help me, but in the concatenation has problem.
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
Jaime OlivaresCommented:
why do you have a dot between Settings.csv and the open bracket?
0
 
ocaccyAuthor Commented:
Hi Jaime, is because i don't know the sintax.
0
 
ocaccyAuthor Commented:
This is good!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now