473,412 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

C# Properties & Method!

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;
}
}

}
Nov 19 '05 #1
3 1128
You cannot have both a property and a method, you'll get naming conflicts.
Cheers,
//Rutger

http://www.RutgerSmit.com
Nov 19 '05 #2
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

"Adam Knight" <de*@brightidea.com.au> wrote in message
news:Of**************@TK2MSFTNGP12.phx.gbl...
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;
}
}

}

Nov 19 '05 #3
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.

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Paul | last post by:
Hello, I've been reading up on security in Java Applets and whilst I understand the concept, I can't successfully get my applet to read a file on my local machine. I discovered from...
0
by: Thomas Scheffler | last post by:
Hi, I runned in trouble using XALAN for XSL-Transformation. The following snipplet show what I mean: <a href="http://blah.com/?test=test&amp;test2=test2">Test1&amp;</a> <a...
12
by: Sammy | last post by:
Hi, my mind is going crazy. I have tried everything I can think of to no avail. I have tried Disable Output Escaping. I tried to think of a way of enclosing the attribute data in a CDATA...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
1
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
17
by: Bruce One | last post by:
Lets consider a class called Currency. This class must be the responsible for taking care of all calculations over currency exchanges, in such a way that I pass values in Euros and it returns the...
3
by: Nathan Sokalski | last post by:
I am adding an onmouseover attribute using the Attributes.Add() method, and the String I am using for the value contains the & character. However, when rendered the & is converted to the HTML...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.