Note that there are some explanatory texts on larger screens.

plurals
  1. POc# passing variables between classes without making them public
    text
    copied!<p>I am writing a WPF application that searches, parses and writes files based on some minimal user input. I have a method call (to a method in another class) in my mainwindow class that requires a number of different pieces of information parsed from two separate files. Currently, I have another method that parses the source files and returns an array of the parsed data for another function of the application. Within that method, I have some public variables to store the necessary info for the first call. This is the only way I can figure how to access those items without writing separate methods to search the parsed data for each individual piece of info I have attached some code to help clarify my current situation:</p> <pre><code>//From mainwindow.xaml.cs private void button1_Click(object sender, RoutedEventArgs e) { string[] path = ff.Search(fw.sysName, fw.design, fw.partNumber);//From FileFinder class string[] parsedData = fp.Parse(path);//From FileProcessor class string[] summary = fw.SummaryWriter(parsedData, fw.masterList);//From FileWriter class Output.Text = ""; foreach (string str in summaryvalues) { Output.Text += (str + "\n"); } } </code></pre> <p>The variables used in ff.Search() and fw.SummaryWriter() are called from FileWriter.cs:</p> <pre><code> class FileWriter { public string sysName; public string design; public string partNumber; public List&lt;string&gt; masterList = new List&lt;string&gt;(); public string[] MasterWriter(string input, int source) { //Do stuff. The data for the public variables is mined from this method. } public string[] SummaryWriter(string[] parsedData, List&lt;string&gt; moduleMasterList) { //Do stuff } } </code></pre> <p>The question I have is simply, how do I access those variables without making them public?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload