Click here to Skip to main content
   

C#

 
GeneralRe: C# app.config permission Pinmemberjschell30-Jan-13 9:07 
QuestionC# linq to sql error Pinmemberclassy_dog29-Jan-13 20:10 
AnswerRe: C# linq to sql error PinmvpRichard MacCutchan29-Jan-13 22:13 
QuestionReference confusion Pinmemberyudhistira dewanata29-Jan-13 19:57 
I've just started learning C# yesterday, and I'm really confused with the reference system.
Can anyone please help explain to me what would happen here:
class Population{
       public void DuplicatePopulation(Population thatPop){
         x=thatPop.x;
       }
       public int x;
};
class GA{
public GA(){
       InitPop=new Population();
       CrossOverPop=new Population();
}
public Population FindPopID(int ID){
       switch(ID){
         case 1:return InitalPop;break;
	 case 2:return CrossOverPop;break;
	 default:break;
       }
       return InitialPop;//default
}
public void DuplicatePopulation(int FromID,int ToID){
	Population FROM,TO;
	FROM=FindPopID(FromID);
	TO=FindPopID(ToID);		         
        TO.DuplicatePopulation(FROM);
}
Population InitialPop,CrossOverPop;
};
 
class MainClass{
public void main(string[] args){
        GA GeneticAl=new GA();
        
        //Process here

        GeneticAl.DuplicatePopulation(1,2);
};
What I'm trying to do is duplicate population Init to Population CO. With this code, will the value of CrossOverPop.x == InitPop.x
Am I already passing by reference? or did i need to use the ref keyword?
AnswerRe: Reference confusion PinmvpAbhinav S29-Jan-13 20:01 
GeneralRe: Reference confusion PinmemberShameel30-Jan-13 4:26 
QuestionSerial Port Errors, User Messages PinmemberC-P-User-329-Jan-13 7:23 
AnswerRe: Serial Port Errors, User Messages Pinmemberjibesh29-Jan-13 12:57 
QuestionDynamic Reference to Dll Path PinmemberMember 461637929-Jan-13 2:53 
AnswerRe: Dynamic Reference to Dll Path PinmemberAlan N29-Jan-13 4:29 

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

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


Advertise | Privacy | Mobile
Web04 | 2.8.150301.1 | Last Updated 3 Mar 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid