C# Properties & Method!

A

Adam Knight

Hi all,

Can I have a class that contains a IsDirector Method & IsDirector property.
The method populates the property.

I have tried the code below..but get a 'definition for IsDirector' already
exists.

Cheers,
Adam

using System;
using System.Web;
public class Security
{
//private variable declarations
private Boolean _IsDirector;
private System.Web.SessionState.HttpSessionState Session;

public Security()
{
//initialise class properties
_IsDirector = IsDirector();
}

public Boolean IsDirector()
{
//determine if a user session is exists
if(null != System.Web.HttpContext.Current.Session)
{
//retrieve session object from page
Session = System.Web.HttpContext.Current.Session;

//determine if logged in user belongs to the directors user group
if ((int)Session("GroupID") = 1)
{
//return boolean indicating user is a director
return true;
}
}

//return boolean indicate user is not a director
return false;
}

public Boolean IsDirector
{
get
{
return _IsDirector;
}
}

}
 
E

Eliyahu Goldin

Adam,

Consider putting the code from the IsDirector method inside the get{..}
clause of the IsDirector property. If you don't want to run this code on
every use of the IsDirector property, introduce another boolean variable
that will tell you if you have already run the code once.

Eliyahu
 
R

riscy

Try changing the name such as

isDirector for Property (1st letter lower case)
IsDirector for Method (1st letter upper case)

or

IsDirectorP for property
IsDirdctor for method

and so on.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,122
Latest member
VinayKumarNevatia_
Top