Solved

C# - To validate this statement

Posted on 2014-04-30
6
154 Views
Last Modified: 2014-05-06
Hello everyone.

How to fix this error? Thanks in advance, ocaccy

m3h = Convert.ToDouble(Settings.csv["csv_" + Xmonth.ToString("00") + "_" + Xhour.ToString("00")]);

Open in new window

This statement returns this error message:
( 'Monitor.Settings.csv' is a 'type', which is not valid in the given context )
The apps has the Settings.cs class; "I have attached a piece of the class code below".
 
    public class Settings
        {
		public class csv
            {
            public static string csv_01_01="2345";
            public static string csv_01_02="1650";
			}
			
	        public static void Write()
            {
            IniFile ini=new IniFile(Monitor.malyt.Folder_users+Monitor.malyt.ConfigINI);
            ini.WriteValue("csv","csv_01_01",csv.csv_01_01.ToString());
            ini.WriteValue("csv","csv_01_02",csv.csv_01_02.ToString());
			}
		}

Open in new window


The file for the app to read the values "file.ini":
[csv]
csv_01_01=1611
csv_01_02=1667
csv_01_03=1714
.
csv_01_24=1560
csv_02_01=2116
csv_02_02=2165
csv_02_03=2212
.
csv_02_24=1569
.
csv_12_24=2063

Open in new window

0
Comment
Question by:ocaccy
  • 4
6 Comments
 
LVL 16

Accepted Solution

by:
Kamal Khaleefa earned 250 total points
ID: 40033868
well, in the  class csv your are only defining strings and not properties to be accessed from out side

you can create an object of settings like this
Settings x = new Settings();

then try to use the object x to access properties inside the class

then when you format your string like "csv_01_01" you need to compare it with the values you have in ur file
0
 
LVL 25

Assisted Solution

by:apeter
apeter earned 250 total points
ID: 40034874
Your Settings is a nested class since it has a class , 'csv' inside.  Also you have all the properties and methods of class 'csv' are static , but the class isn't. So for the 'csv' for to access its method it has also a static class.

Also in your code you are trying to access the csv properties as indexers. And we can't do that because of your csv structure. If you want to access them as indexers then you should have your TWO properties in csv class as type Dictionary.
0
 

Author Comment

by:ocaccy
ID: 40036106
Thank you @king2002 and apeter; I`m using the information passed for you to use in my code. I`ll be back soon.
ocaccy
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ocaccy
ID: 40036444
So, the app has this static properties:
                monthHour[1, 1] = Convert.ToDouble(Settings.csv.csv_01_01);
                monthHour[1, 2] = Convert.ToDouble(Settings.csv.csv_01_02);
                monthHour[1, 3] = Convert.ToDouble(Settings.csv.csv_01_03);
                monthHour[1, 4] = Convert.ToDouble(Settings.csv.csv_01_04);
                monthHour[1, 5] = Convert.ToDouble(Settings.csv.csv_01_05);

Open in new window


Settings x = new Settings(); I need create this object where? setting.cs!?
0
 

Author Comment

by:ocaccy
ID: 40036449
@apeter,
 If you want to access them as indexers then you should have your TWO properties in csv class as type Dictionary.

How?
0
 

Author Closing Comment

by:ocaccy
ID: 40046063
Thank you,
ocaccy.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now