Click here to Skip to main content
15,892,480 members
Home / Discussions / C#
   

C#

 
Questionneed a clarification Pin
prasadbuddhika30-Jun-10 6:41
prasadbuddhika30-Jun-10 6:41 
AnswerRe: need a clarification Pin
Ennis Ray Lynch, Jr.30-Jun-10 6:46
Ennis Ray Lynch, Jr.30-Jun-10 6:46 
AnswerRe: need a clarification Pin
Pete O'Hanlon30-Jun-10 7:17
mvePete O'Hanlon30-Jun-10 7:17 
GeneralRe: need a clarification Pin
Ennis Ray Lynch, Jr.30-Jun-10 7:25
Ennis Ray Lynch, Jr.30-Jun-10 7:25 
GeneralRe: need a clarification Pin
Pete O'Hanlon30-Jun-10 7:28
mvePete O'Hanlon30-Jun-10 7:28 
GeneralRe: need a clarification Pin
Ennis Ray Lynch, Jr.30-Jun-10 7:32
Ennis Ray Lynch, Jr.30-Jun-10 7:32 
GeneralRe: need a clarification Pin
Pete O'Hanlon30-Jun-10 7:36
mvePete O'Hanlon30-Jun-10 7:36 
QuestionVery basic beginners confusion over public properties [modified] Pin
Daley8330-Jun-10 5:50
Daley8330-Jun-10 5:50 
Ok so I'm looking to get my knowledge and skills up to par and I've started a small project to get my head around a few things but I've already found something that is confusing me. I've posted a very stripped down version for simplicity.

I am intending to run a method(runApple) from a derived class(Apple) that will set default values.

My Base.cs page contains;

public class FruitBase
{
//Private fields
private string _Name;

//Constructor
public FruitBase()
{
}

//Properties
public string Name
{
get { return _Name; }
set { _Name = value; }
}
}

public class Apple: FruitBase
{
public Apple()
{
}

public void runApple()
{
Apple a = new Apple();

a.Name = "Apple";
}

}

And my Default.aspx page has the function below that is fired on a button press:
public void Start(object sender, EventArgs e)
{
Apple a1 = new Apple();

a1.runApple();

txtOuput.Text = a1.Name;

}

Now when debugging I step into the code at the a1.runApple(); line which takes me to the set section of the FruitBases public property Name. Whilst in there the value updates the string so that it equals "Apple", however as soon as the cursor returns to the runApple methods closing curly brace all the Name values return to Null.

I know that I can set the value within the Start() method by doing a1.Name = "Apple" but i want to build up lots of different properties so it makes sense to run them all at once from the runApple method. The intention is to scale this up to have many more FruitBase fields and many more derived classes with relevant defaults eg banana, grape, orange etc.

I realise this is a very basic isse but we all have to start somewhere right? Thanks for your time.

modified on Wednesday, June 30, 2010 12:18 PM

AnswerRe: Very basic beginners confusion over public properties Pin
Ravi Bhavnani30-Jun-10 6:04
professionalRavi Bhavnani30-Jun-10 6:04 
GeneralRe: Very basic beginners confusion over public properties Pin
Daley8330-Jun-10 6:08
Daley8330-Jun-10 6:08 
GeneralRe: Very basic beginners confusion over public properties Pin
Ravi Bhavnani30-Jun-10 6:10
professionalRavi Bhavnani30-Jun-10 6:10 
AnswerRe: Very basic beginners confusion over public properties Pin
harold aptroot30-Jun-10 6:05
harold aptroot30-Jun-10 6:05 
GeneralRe: Very basic beginners confusion over public properties Pin
Daley8330-Jun-10 6:10
Daley8330-Jun-10 6:10 
GeneralRe: Very basic beginners confusion over public properties Pin
harold aptroot30-Jun-10 6:11
harold aptroot30-Jun-10 6:11 
AnswerRe: Very basic beginners confusion over public properties Pin
Keith Barrow30-Jun-10 6:11
professionalKeith Barrow30-Jun-10 6:11 
GeneralRe: Very basic beginners confusion over public properties Pin
Daley8330-Jun-10 6:20
Daley8330-Jun-10 6:20 
AnswerRe: Very basic beginners confusion over public properties Pin
Ennis Ray Lynch, Jr.30-Jun-10 6:12
Ennis Ray Lynch, Jr.30-Jun-10 6:12 
GeneralRe: Very basic beginners confusion over public properties Pin
harold aptroot30-Jun-10 6:14
harold aptroot30-Jun-10 6:14 
GeneralRe: Very basic beginners confusion over public properties Pin
Daley8330-Jun-10 6:17
Daley8330-Jun-10 6:17 
GeneralRe: Very basic beginners confusion over public properties Pin
Ennis Ray Lynch, Jr.30-Jun-10 6:28
Ennis Ray Lynch, Jr.30-Jun-10 6:28 
QuestionHow to show tooltip on the button Pin
undynamicmagic30-Jun-10 4:52
undynamicmagic30-Jun-10 4:52 
AnswerRe: How to show tooltip on the button Pin
Peace ON30-Jun-10 4:58
Peace ON30-Jun-10 4:58 
GeneralRe: How to show tooltip on the button Pin
undynamicmagic30-Jun-10 5:52
undynamicmagic30-Jun-10 5:52 
QuestionUsing a Chart Control in Vs 2010 [modified] Pin
It_tech30-Jun-10 4:33
It_tech30-Jun-10 4:33 
QuestionCorrect marshalling? C# callback from C++ DLL Pin
ProfAndyZulu30-Jun-10 3:14
ProfAndyZulu30-Jun-10 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.