|
-
July 13th, 2005, 09:35 AM
#1
calling static methods
i've the following code and I want to call in the first function the ParserHelper method without instantiating an object (Form1 f=new Form1() ), how to do that?? The declaration of ParserHelper is as follows:
public String ParserHelper (String fileName, String num, String headers)
I tried making it static and then calling it but it gave me errors. So how shud i do it correctly??
Code:
namespace HL7Convert
{
/// <summary>
/// Summary description for Converter.
/// </summary>
class HL7Convert
{
class HL7Viewer
{
public String Parser(String fName, String fNum, String header)
{
Form1 f=new Form1();
return (f.ParserHelper(fName,fNum, header));
}
}
public String HL7 (String fileName, String fileNumber, String headers)
{
HL7Viewer c = new HL7Viewer();
return c.Parser(fileName, fileNumber, headers);
}
public static void Main()
{
String text;
HL7Convert ct= new HL7Convert();
text=ct.HL7("test.txt","324", "st tt ");
Console.WriteLine(text);
Console.ReadLine();
}
}
}
-
July 13th, 2005, 01:34 PM
#2
Re: calling static methods
you said your declaration is as follows:
public String ParserHelper (String fileName, String num, String headers)
you didnt specify the static keyword.
it should be
public static String ParserHelper (String fileName, String num, String headers)
hope this helps.
CafeDreamz.
-
July 13th, 2005, 01:37 PM
#3
Re: calling static methods
hey,also make sure the Parserhelper method is not accessing any non-static instance members of the class to which it belongs.
-
July 13th, 2005, 02:29 PM
#4
Re: calling static methods
yea i had tried by putting static, cuz thts necessary if i dont want to make an object to call the function, but when i call in this HL7Convert class it says it doesn't belong to name space and stuff, although i've created a dll of the class where the ParserHelper and included here:
Code:
using System;
using WindowsApplication1;
Also, ParserHelper was calling other function too, and i made that static too. But nothing worked
-
July 13th, 2005, 02:34 PM
#5
Re: calling static methods
ok i figured my prob, i wasn't calling it rite..its supposed to be like this:
return (Form1.ParserHelper(fName,fNum, header));
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
|