Click here to Skip to main content
15,914,111 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to call 1 class method or constructor in other class ? Pin
Henry Minute21-May-09 6:42
Henry Minute21-May-09 6:42 
GeneralRe: how to call 1 class method or constructor in other class ? Pin
xingselex21-May-09 6:45
xingselex21-May-09 6:45 
GeneralRe: how to call 1 class method or constructor in other class ? Pin
xingselex21-May-09 7:05
xingselex21-May-09 7:05 
GeneralRe: how to call 1 class method or constructor in other class ? Pin
harold aptroot21-May-09 7:07
harold aptroot21-May-09 7:07 
GeneralRe: how to call 1 class method or constructor in other class ? Pin
xingselex21-May-09 7:11
xingselex21-May-09 7:11 
GeneralRe: how to call 1 class method or constructor in other class ? Pin
OriginalGriff21-May-09 8:31
mveOriginalGriff21-May-09 8:31 
GeneralRe: how to call 1 class method or constructor in other class ? Pin
harold aptroot21-May-09 7:06
harold aptroot21-May-09 7:06 
GeneralRe: how to call 1 class method or constructor in other class ? Pin
musefan21-May-09 6:37
musefan21-May-09 6:37 
As Henry has said, you can access it the way you are trying only if the S string is static and publicly available. Which I am guessing is not the case.

ensure you DataConnection class is similar to the following...

public class DataConnection
{
   private string s = "default";//this is where the string value will be stored, assignment is not required
   public string S{//this is a property that you can access with external class to get/set the value of the private string s
   { 
      get{return s;}
      set{s = value;}
   }
}


then in your main form you need to create an instance of your DataConnection class in which you can access the value of S, like so...

DataConnection dc = new DataConnection();
dc.S = "new value";
MessageBox.Show(dc.S);


you need to ensure that your DataConnection instance is located in an appropriate place depending on where you want to access the data from i.e. mulitply functions would mean you should set it at a class level

Life goes very fast. Tomorrow, today is already yesterday.

QuestionGet/Set for List<string> in C#</string> Pin
ipstefan21-May-09 3:07
ipstefan21-May-09 3:07 
AnswerRe: Get/Set for List in C# Pin
musefan21-May-09 3:12
musefan21-May-09 3:12 
GeneralRe: Get/Set for List in C# Pin
ipstefan21-May-09 3:15
ipstefan21-May-09 3:15 
GeneralRe: Get/Set for List in C# Pin
musefan21-May-09 3:20
musefan21-May-09 3:20 
AnswerRe: Get/Set for List in C# Pin
Anthony Mushrow21-May-09 3:18
professionalAnthony Mushrow21-May-09 3:18 
GeneralRe: Get/Set for List in C# Pin
ipstefan21-May-09 3:49
ipstefan21-May-09 3:49 
AnswerRe: Get/Set for List in C# Pin
Luc Pattyn21-May-09 3:36
sitebuilderLuc Pattyn21-May-09 3:36 
GeneralRe: Get/Set for List in C# Pin
musefan21-May-09 3:45
musefan21-May-09 3:45 
GeneralRe: Get/Set for List in C# Pin
PIEBALDconsult21-May-09 4:09
mvePIEBALDconsult21-May-09 4:09 
GeneralRe: Get/Set for List in C# Pin
Luc Pattyn21-May-09 4:21
sitebuilderLuc Pattyn21-May-09 4:21 
GeneralRe: Get/Set for List in C# Pin
musefan21-May-09 4:37
musefan21-May-09 4:37 
GeneralRe: Get/Set for List in C# Pin
Paddy Boyd21-May-09 5:24
Paddy Boyd21-May-09 5:24 
GeneralRe: Get/Set for List in C# Pin
Luc Pattyn21-May-09 5:30
sitebuilderLuc Pattyn21-May-09 5:30 
Questionexcel x-axis in Time format 00:00:00 using C# Pin
carnister21-May-09 2:49
carnister21-May-09 2:49 
QuestionSave to default program files folder Pin
Jon Henry21-May-09 2:30
Jon Henry21-May-09 2:30 
AnswerRe: Save to default program files folder Pin
musefan21-May-09 2:35
musefan21-May-09 2:35 
AnswerRe: Save to default program files folder [modified] Pin
Luc Pattyn21-May-09 3:41
sitebuilderLuc Pattyn21-May-09 3:41 

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.