On a C # form application
I want to assign the character entered in the text to a variable and use it for other processing.
I'm sorry for beginners and stubborn content. Thank you.
C #
namespace WindowsFormsApp2
{
public partial class Form1: Form
{
public Form1 ()
{
InitializeComponent ();
}
private void OnTagsReported (ImpinjReader sender, TagReport report) // Move when information is acquired from the sensor
{
if (moji == "0001") // I want to use moji's variable obtained with Button1_Click as it is.
{
// Process
}
}
private void Button1_Click (object sender, EventArgs e)
{
string moji = textBox1.Text;
}
}
}
`` `
-
Answer # 1
-
Answer # 2
The
moji
declared in theButton1_Click
method is a local variable and a variable local to the method. Therefore, it cannot be taken out of the method.
In order to notify the outside, input is received from the outside by reference or notified as a return value.
But since it's a button click event handler, the signature cannot be changed.
Therefore, it can be referenced in the class as a class variable.Please click "
" to enter the source code in the `` `entered.
-
Answer # 3
Roughly speaking, the accessible range of a variable depends on where it is declared.
Learn about variable scope.
Related articles
- i want to pass perl variables to php
- i want to pass the structure secured in c # to c ++
- java - i want to pass list type data obtained from db to view
- java - i want to pass information from jsp to servlet
- c # - what is the difference between delegate variables and delegate types?
- c # - i want to share variables from other scripts
- php - i want to pass music data from db to tag
- php - i want to pass the image file to the server
- i want to pass an image from python to c ++
- c # - [unity] i want to start the variables of the script of multiple generated objects individually
- c # - i want to read a large excel file with npoi
- sql server - i want to pass ":" from a batch file to a sql statement
- c # - unity i want to access script variables attached to other objects
- c # - i want to dynamically generate tags in aspx
- i want to pass the php path
- c # - i want to know the intent of mvvm "viewmodel must not know view"
- c # - the values of the variables declared individually in list will be the same! ??
- c # - i want to get a datatable with linq and then outer join
- c # - i want to play animator every time i tap
- c # - i want to replace a file with the same name in asset
- c # - get variable values from aspnet code-behind
- unable to add c # systemwindowsformsform
- c # - toolbox is not displayed even on the screen of visual studio design
- c # - it appears in the console window even though it is different from the condition of the unity if statement
- c # - i want to display my form as new after sleeping for a few seconds
- c # - i want to share variables from other scripts
- get audio in c # and display waveform
- c # - i want to specify a different url from the script side for the video player component of unity
- candidates are not displayed even if i hit a period in c # opened in unity
- how do i switch between multiple programs in visual studio c #?
By defining
class member variables as
string _moji
, member variables can be used for methods in the same class.