Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Any idea if in combobox exist feature that make display member with biggest value member?
Thank you in advance.
Since you didn't show any effort or code example, you can follow a structure like this;
int biggest = comboBox1.Items[0];
for (int i = 1; i < comboBox1.Items.Length; i++)
{
biggest = GetBigger(comboBox1.Items[i], biggest);
}
comboBox1.SelectedItem.Value = biggest;
static int GetBigger(int a, int b)
{
if (a < b)
return b;
return a;
}
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
Ok so i'm halfway into the semester in a C# coding class and I just have a simple question.
When Im reading others code I see people do something like this:
string exampleString = new string();
StreamReader exampleSr = new StreamReader();
Int exampleInt = new int();
char a = new Char();
I have a few questions:
For like the String one, wouldn't it be the same if I just did
string exampleString = " ";?
What do people use these for?
And also what goes inside the parenthesis?
Just a few simple questions, im not sure what to search up to my find the answer to my questions so im asking here, Thanks!
In the case of the string, string a = ""; is not the same as string b = new string();.
Why:
a is now set to literally "", that means an empty string.
trying to define b in the way shown above will result in an error, because the constructor of string is not defined for 0 arguments.
you can declare a cariable like this, too:
string c;
this will result in an empty variable with no value in it (yet).
you'll have to assign it a value before you can use it, though (otherwise you'll get an error).
I'm not sure if i gave you a useful answer, so please ask me if you have any further questions.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
select cast(' ' as varchar(1000)) as myfield, otherfield
from tab1;
I need to convert above SQL to Linq-To-Sql.
Maybe:
from item in dataContext.Items
select new { MyField = "", Item = item };
Unfortunately, AMAIK, there is no way to declare * in projection in LINQ. Thus to have all other fields alongside your MyField field, you should write them all.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
As it says in the title, is there a code to find out the total of all the numbers in an int array element.
E.G
int [] Football = new int [5];
And say all the elements already had values, how would i find the total of them or reference the total of them so i could add it to a variable?
That is quite easy using LINQ:
Football.Sum();
You need to iterate over the elements. This is basic stuff and should be covered in any C# tutorial:
int total = 0;
foreach(int i in Football) {
total += i;
}
Or you can use LINQ:
int total = Football.Sum();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Could anyone please suggest, I have a datatable with 100 records and want to update any 1 specific record based on id.
Here is an example, maybe it helps even if your reqirement is not that clear:
DataRow row = tableWith100Rows.AsEnumerable()
.FirstOrDefault(r => r.Field<int>("ID") == 4711);
if(row != null)
row.SetField("ColumnToUpdate", "new value");
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a combobox, and I would like to search through every element in it.
How can I do this? (also the number of items is not the same everytime, but this is not so important).
I am using c# windows form application.
you can do this
for (int i = 0; i < myComboBox.Items.Count; i++)
{
string value = myComboBox.GetItemText(myComboBox.Items[i]);
}
Use a foreach loop. It will iterate all your items of ComboBox regardless of their count, e.g.
foreach(var item in myComboBox.Items)
{
// do something with your item
}