Click here to Skip to main content
15,915,600 members
Home / Discussions / C#
   

C#

 
QuestionProblem with events Pin
sciamachy24-Nov-05 5:48
sciamachy24-Nov-05 5:48 
AnswerRe: Problem with events Pin
Leslie Sanford24-Nov-05 6:58
Leslie Sanford24-Nov-05 6:58 
QuestionTreeView question. Pin
zaboboa24-Nov-05 4:26
zaboboa24-Nov-05 4:26 
AnswerRe: TreeView question. Pin
Robert Rohde24-Nov-05 4:39
Robert Rohde24-Nov-05 4:39 
QuestionMethod parameters Pin
1nsp1r3d24-Nov-05 3:15
1nsp1r3d24-Nov-05 3:15 
AnswerRe: Method parameters Pin
Leslie Sanford24-Nov-05 3:40
Leslie Sanford24-Nov-05 3:40 
GeneralRe: Method parameters Pin
Colin Angus Mackay24-Nov-05 4:15
Colin Angus Mackay24-Nov-05 4:15 
AnswerRe: Method parameters Pin
Colin Angus Mackay24-Nov-05 4:25
Colin Angus Mackay24-Nov-05 4:25 
1nsp1r3d wrote:
I thought that all reference types were passed by reference and all value types by value(enums and ints/floats/etc)? Is that the case?


Yes, you are correct.

Consider this small application:
using System;
 
namespace ConsoleApplication12
{
    class A
    {
        private string someValue;

        public string SomeValue
        {
            get
            {
                return this.someValue;
            }
            set 
            {
                this.someValue = value;
            }
        }
    }
 
    class Class1
    {
        [STAThread]
        static void Main(string[] args)
        {
            Console.WriteLine("In the Main method");
            A mainA = new A();
            mainA.SomeValue = "This was set in the main method";
            Console.WriteLine(mainA.SomeValue);
            AnotherMethod(mainA);
            Console.WriteLine(mainA.SomeValue);
            Console.ReadLine();
        }
 
        static void AnotherMethod(A parameterA)
        {
            Console.WriteLine("In AnotherMethod");
            Console.WriteLine(parameterA.SomeValue);
            parameterA.SomeValue = "This value was set in AnotherMethod";
            Console.WriteLine(parameterA.SomeValue);
            Console.WriteLine("Exiting AnotherMethod");
        }
    }
}


The output would be:
In the Main method
This was set in the main method
In AnotherMethod
This was set in the main method
This value was set in AnotherMethod
Exiting AnotherMethod
This value was set in AnotherMethod


As you can see, the object of class A is passed by reference because when its property is updated in the method, the update is reflected in the Main method after the call.

Does this help?


My: Blog | Photos

"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious


GeneralRe: Method parameters Pin
Leslie Sanford24-Nov-05 4:46
Leslie Sanford24-Nov-05 4:46 
GeneralRe: Method parameters Pin
Colin Angus Mackay24-Nov-05 4:58
Colin Angus Mackay24-Nov-05 4:58 
GeneralRe: Method parameters Pin
Leslie Sanford24-Nov-05 5:34
Leslie Sanford24-Nov-05 5:34 
GeneralRe: Method parameters Pin
Colin Angus Mackay24-Nov-05 5:44
Colin Angus Mackay24-Nov-05 5:44 
AnswerRe: Method parameters Pin
Colin Angus Mackay24-Nov-05 5:02
Colin Angus Mackay24-Nov-05 5:02 
QuestionData types in reports (rdls) Pin
doph24-Nov-05 1:50
doph24-Nov-05 1:50 
QuestionConverting decimal to String Pin
Subrahmanyam K24-Nov-05 1:37
Subrahmanyam K24-Nov-05 1:37 
AnswerRe: Converting decimal to String Pin
J4amieC24-Nov-05 2:02
J4amieC24-Nov-05 2:02 
AnswerRe: Converting decimal to String Pin
Craig G Fraser24-Nov-05 2:04
Craig G Fraser24-Nov-05 2:04 
QuestionRegarding Strong name Pin
A.Grover24-Nov-05 1:23
A.Grover24-Nov-05 1:23 
AnswerRe: Regarding Strong name Pin
S. Senthil Kumar24-Nov-05 2:19
S. Senthil Kumar24-Nov-05 2:19 
GeneralRe: Regarding Strong name Pin
A.Grover24-Nov-05 23:14
A.Grover24-Nov-05 23:14 
Questionclient/server communication Pin
batmanAgen24-Nov-05 1:08
batmanAgen24-Nov-05 1:08 
QuestionGenetating XML Pin
Gktony24-Nov-05 0:56
Gktony24-Nov-05 0:56 
AnswerRe: Genetating XML Pin
J4amieC24-Nov-05 1:33
J4amieC24-Nov-05 1:33 
GeneralRe: Genetating XML Pin
Gktony24-Nov-05 3:06
Gktony24-Nov-05 3:06 
GeneralRe: Genetating XML Pin
J4amieC24-Nov-05 4:32
J4amieC24-Nov-05 4:32 

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.