accessing non-static members from static method

J

Jeff

Hi

..NET 2.0

I'm rewriting a method to become a static method, because FindCommentById is
called from a static method. Which gives me several compile errors

private static Comment FindCommentById(Guid id)
{
if (Comment.Id == id) <<<---- see implmentation of Id below this
method
return this; <<<--- "this" is not valid in static property
else
{
Comment parent = null;
foreach (Comment comment in Replies) <<<---- Replies is a
collection of Comments associated with a comment, not sure to write that
static
{
parent = Comment.FindCommentById(id);
}
return parent;
}
}

*****
private Guid _id;
public Guid Id
{
get { return _id; }
set { _id = value; }
}

I know that I cannot call Id from FindCommentById because Id is not static.
I tryed to make a static method as well (public static Guid Id), but that
didn't work out as well....

any suggestions?
 
J

Jeff

the reason I started to convert that method into a static is because it is
being accessed by another static method

In my code I have this method:
public static List<Comment> GetComments(Guid id)
{
}
which return a collection of comments, this method is used as SelectMethod
in a GridView (asp.net 2.0). This method again makes a call to
FindCommentById, So I thought I should convert FindCommentById into a static
method... On the other hand maybe I should convert GetComments into a
non-static method and then don't use it as SelectMethod, but instead just
call the method programmatically in for example Page_Load event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top