-
January 6th, 2014, 08:16 PM
#1
How to access other class members in C#
I'm having difficulty accessing other class members. I have created other class objects to access their member fields. The code compiles but I don't get any results back when I display them.
I've searched here and googled unsuccessfully to find an answer to my question. Can someone show me what I have overlooked? Below is a snippet of the code involved.
Thank you very much, Kent
Code:
// this class I want to use the value of ChFreq from another class
public class Lru_Channel_Details
{
public void actualFreq()
{
Lru_operation LruOp2 = new Lru_operation(); // create main operations class object to access ChFreq
Lru_SetChanFreq LruSetChFreq1 = new Lru_SetChanFreq(); // create other class object to access ChFreq
Console.WriteLine("LruOp2.SetChanFreq.ChFreq = {0}", LruOp2.SetChanFreq.ChFreq); // fails to display the ChFreq value
Console.WriteLine("LruSetChFreq1.ChFreq = {0}", LruSetChFreq1.ChFreq); // also fails to display the value
}
}
// in this class, I have set the values of ChFreq to 405.0
public class Lru_SetChanFreq
{
private string chFreq;
public string ChFreq
{
get { return chFreq; }
set { chFreq = value; }
}
public void SetFreq()
{
Lru_operation LruOp1 = new Lru_operation(); // this object accesses multiple other classes
LruOp1.SetChanFreq.ChFreq = "405.0"; // assign this value using main operations class object
LruOp1.ChanDet.actualFreq(); // calls another class method to use ChFreq
// does stuff with LruOp1 to access other class methods (not shown)
}
}
// this class is my main operations class. the below objects are used to access other
// class members from this class
public class Lru_operation
{
public Lru_SetChanFreq SetChanFreq = new Lru_SetChanFreq();
public Lru_Channel_Details ChanDet = new Lru_Channel_Details();
// does stuff with the above class objects' methods
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|