-
Junior Member
Get out put without taking argument
Doubt in a program using static methods and static classes
In the below program in the static method I am taking a argument string s.
Without taking a argument, how can I get the same output ie “hi”,
but I should use static methods and static classes.
// In general declaration
static class test
{
public static void show(String s)
{
MessageBox.Show(s);
}
}
private void button1_Click(object sender, EventArgs e)
{
test.show("HI");
// test t = new test();
}
-
Junior Member
Re: Get out put without taking argument
// In general declaration
static class test
{
public static s as string; // Declare static variable . so that u can use in any one class by using (test.s)
public static void show()
{
MessageBox.Show(s);
}
}
private void button1_Click(object sender, EventArgs e)
{
s="HI"; // put the data into static variable s . If ur using in the same class then u can use s directlry. Other wise u have to use s after class name(eg. test.s="HI"
}
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