It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have tried something like: "GetLine(fileName,line)" no luck
Code:
static void Main(string[] args)
{
GetLine();
}
string GetLine(string fileName, int line)
{
......
}
You are calling the GetLine declared non-static from within a static function.
Either mark the GetLine declaration as static, or create an instance of the class containing both the functions.
it should be a static method if you want to call directly like that.
private static string GetLine(string fileName, int line)
If you want to overload the method GetLine it must be marked with the virtual indicator.
virtual string GetLine(string fileNmae, int line)
{
//Code for method goes here
}
Update :
As Mario Vernari suggested you will need to make the method static.
If you want to call the method like this GetLine() then you will need to create a new overloaded method for GetLine.
static string GetLine()
{
return "Some string message"; //Return a string.
}
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
wrote this code which calls Async function once on button click.
But i want it to run continuously updating the Page variable on every loop.
example: 1st loop page = 1 second loop page =2 so on.. and stop the loop on another button click.
private void button2_Click(object sender, EventArgs e)
{
var searchParameters = new PlayerSearchParameters
{
Page = 2,
League = League.BarclaysPremierLeague,
Nation = Nation.England,
Position = Position.CentralForward,
Team = Team.ManchesterUnited
};
LoginM.SearchItemsAsync(searchParameters);
}
Sorry for not giving a detailed explanation/
The searchParamters are obtained from textboxes and sent to a Async function on LoginM.cs file by calling :
LoginM.SearchItemsAsync(searchParameters);
I want LoginM.SearchItemsAsync(searchParameters); to be called continuously and each time it gets called the "Page" variable should be incremented by +1
How do i create a loop to do the above ?
Its a WinForm Project.
You'll need a place to hold your current value, in the example I've made it to be a local named pageNum. Inside your loop then, you'll increment that variable and assign it to the Page property on the PlayerSearchParameters object being constructed in its initializer.
If you want the method to wait for the async method to be completed before starting the next iteration of the loop, make the event handler async and await the result of the one you're calling.
private async void button2_Click(object sender, EventArgs e)
{
var pageNum = 0;
while(true) //<-- Insert whatever your real condition is here instead of true
{
var searchParameters = new PlayerSearchParameters
{
Page = ++pageNum,
League = League.BarclaysPremierLeague,
Nation = Nation.England,
Position = Position.CentralForward,
Team = Team.ManchesterUnited
};
await LoginM.SearchItemsAsync(searchParameters);
}
}
If you're trying to get this behavior without having to click a button first, you could put the body of the method in a handler for the Load event on your form instead.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am not able to figure how will this work:
public Class1 Function1()
{
DataTable dt;
try
{
dt = new DataTable();
//.. Do some work
return new Class2(byref dt);
}
finally
{
dt.dispose();
}
}
public Class2(byref DataTable dTable)
{
this.dataTable = dTable;
}
So, now if I say Class1 obj1 = Function1(); will my obj1.dataTable be disposed? or it will have proper data?
yes assuming obj1.dataTable refers to the same object you created inside Function1, it will have been disposed. Finally blocks are always executed, regardless of whether an exception is thrown or not.
Here's some more information on try-finally blocks.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm doing C# And now I want to learn about VB.Net, and I want the equivalent for this:
Hide();
using (login loginForm = new login())
{
var result = loginForm.ShowDialog();
if (result == DialogResult.OK)
{
Show();
}
else
{
Close();
}
}
Hide()
Using loginForm As New login()
Dim result = loginForm.ShowDialog()
If result = DialogResult.OK Then
Show()
Else
Close()
End If
End Using
What did you try yourself? Just look up each thing on MSDN (Using statement, If statement, ...) and look at the code examples in VB.
Anyway, here is the converted code:
Hide()
Using loginForm As New login()
Dim result = loginForm.ShowDialog()
If result = DialogResult.OK Then
Show()
Else
Close()
End If
End Using
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How can I prevent a ListView option from changing?
I have tried the following, however it still changes:
bool q=false;
private void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (q)
{
// Let change happen
}
else
{
// Stop change from happening
return;
}
}
Thank you for any help.
Save the prior value and then reset it to the prior.
int lastIndex = -1;
if (q)
{
lastIndex = (ListView)Sender.SelectedIndex;
}
else
{
// Stop change from happening
(ListView)Sender.SelectedIndex = lastIndex;
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
i am using visual studio 2008 c# winform. . i've make sudoku game which is working well . . i want to make best player screen for it and score depend on how much time the player take to complete game . .
i am using another form to take player name when he meets the condition for best player and give the name to label on main form but its not working.here is my code:
private void button1_Click(object sender, EventArgs e)
{
Form1 main = new Form1();
main.lbBEN.Text = textBox1.Text;
this.Close();
}
and this on another form:
if (emint<bmint)
{
best b = new best();
b.ShowDialog();
}
please guide me. . .THANK you
Add a public property to the second form and just below the ShowDialog(), sets the form1 label.Text to that property containing the name of the user.
public partial class Form2 : Form
{
string _highestScoreUser = string.Empty;
public Form2()
{
}
public string HighestScoreUser
{
get{ return _highestScoreUser; }
set{ _highestScoreUser = value; }
}
}
In Form1 code after ShowDialog is called like
{
Form2 form = new Form2();
form.ShowDialog();
form1.label.Text = form.HighestScoreUser;
}
Hope this help
You've created a brand new Form1 object unrelated to the Form1 that is already on the screen. You need to somehow pass a reference to the real Form1 the the secondary form.