|
-
Feb 10th, 2011, 03:54 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Cannot access function from class
Hi i am trying to make my own little config reader for my programs I got most of it working but i am haveing troble trying to return a list from a class, evey time i type the class name the list function does not show up in the list eveything else works fine, I left my class code here so maybe someone can see what i am doing wrong thanks.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace TestConfig{
public class MyConfig
{
private string _Filename;
private static Dictionary<string, string> Lines = new Dictionary<string, string>();
public MyConfig(string localname)
{
this._Filename = localname;
string sLine;
int cnt = 0;
//Check if file is here
if (!File.Exists(localname))
{
throw new FileNotFoundException("File Not Found:\n" + this._Filename);
}
else
{
using (StreamReader sr = new StreamReader(this._Filename))
{
while (!sr.EndOfStream)
{
sLine = sr.ReadLine().Trim();
//Check for comments
if (sLine.StartsWith("//"))
{
cnt++;
Lines.Add(cnt.ToString(), sLine);
}
else
{
//Get position of space
int spos = sLine.IndexOf(" ");
//Check for space position
if (spos != -1)
{
//Extract key
string sKey = sLine.Substring(0, spos).ToLower();
//Extract value
string sValue = sLine.Substring(spos + 1, sLine.Length - spos - 1);
//Add to the dir
Lines.Add(sKey, sValue);
}
}
}
}
}
}
public static List<string> Keys()
{
List<string> items = new List<string>();
items.AddRange(Lines.Keys);
return items;
}
public string ReadValue(string keyname)
{
try
{
return Lines[keyname];
}
catch
{
return "";
}
}
}
}
-
Feb 10th, 2011, 04:49 PM
#2
Re: Cannot access function from class
You made it "static". If you wanted it such, you can access it by typing MyConfig.Keys() instead of a specific instance. (Static methods exist on the class, not on any specific instance.)
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Feb 10th, 2011, 05:01 PM
#3
Thread Starter
Fanatic Member
Re: Cannot access function from class
k Thanks chnage it now to public and it works was not sure about that static thing like, thanks for the help. was driveing me nuts.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|