|
how is medie_sim defined ? let me guess - also an Int ?
|
|
|
|
|
|
It's the same problem as your other code - integer division.
15 / 8 = 1.875 , but since the variables are integers, only the integer part is used: 15 / 8 = 1 - You then multiply that result by
100 , which (unsurprisingly) gives a final result of 100 . - You then store that final result in a
double , but it's too late - you've already lost the fractional part at step 1.
You need to convert one of the values to a floating-point type before the division:
medie_sim = ((double)totalsim / totalsimyes) * 100;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
May I know how should we extract the individual colour chart from GUI to display the result of RGB, HSI and Lab?
|
|
|
|
|
|
I want to insert an image in database. But if I don't choose any image, I receive : Empty path name is not legal . In database, image field is BLOB and is null. Where is my mistake cause I can't figure it out..I think that I should verify if textBox5 is null and if is, imageBt=null . I tried this but it didn't worked. This is the code that I'm using to insert the image:
byte[] imageBt = null;
FileStream fstream = new FileStream(this.textBox5.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fstream);
imageBt = br.ReadBytes((int)fstream.Length);
SQLiteCommand com = new SQLiteCommand("insert into questions(image) values(@IMG)", Conexiune.getConnection());
com.Parameters.Add(new SQLiteParameter("@IMG", imageBt));
com.ExecuteNonQuery();
|
|
|
|
|
Try this instead of just checking for null:
if (!String.IsNullOrWhiteSpace(textBox5.Text))
{
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Where should I put this?..
|
|
|
|
|
"Around" your posted code. Or what Pete replied before your posted code (that if (!File.Exists(textBox5.Text)) that he posted also).
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Gosh it was so easy..I think I'm tired ) Sorry for this boring question. Thank you!
|
|
|
|
|
Hehe, alright
To cover that topic in a general statement: Always check your inputs before trusting them.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
First of all, you should name your textboxes with a more meaningful name. Then, you really want to test some validity like this:
if (string.IsNullOrWhitespace(textBox5.Text)) return;
if (!File.Exists(textBox5.Text)) return;
|
|
|
|
|
Where should I put this?..
|
|
|
|
|
Before the point that your code blows up would probably seem a sensible place don't you think?
|
|
|
|
|
I managed to fix it. Gosh it was so easy..I think I'm tired ) Sorry for this boring question. Thank you!
|
|
|
|
|
What are the specific rules to name a C# source file? I came across many posts about this issue but all are about special cases. For example, Microsoft's page about this topic does not really get to the point.
https://msdn.microsoft.com/en-us/library/ms228500%28v=vs.90%29.aspx[^]
I need clear and to-the-point answers. Is a C# source file name arbitrary? I am using code samples from several C# books and the samples tend to pick up the name of the top (non-nested) class in the file or the name of namespace, or maybe something else. I have not tried to play with this yet but my feeling is that the file name could be just arbitrary. Is it correct? What are the imposed restrictions on file name and what are the actual guidelines?
|
|
|
|
|
Well, it sort of gets to the point:
Quote: Unlike Java, source files can contain more than one top-level public class declaration, and the file name does not need to match any of the classes' names. So you wouldn't violate an official naming rule by naming your files what you deem most appropriate. Normally they should contain only one class and have the same name as that class because that's what's most intuitive.
In my opinion, it sometimes makes sense to have more than one class in a source file. In that case I would name the file like the class that is either the base class or represents the functionality that is most important within that source file. In some cases, e.g. lots of small classes that serve a very similar purpose, I put them all in a single source file and name it according to the purpose of those classes. But it should remain the exception from the rule.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
There are no real rules around the way you name class files, but something to consider is what the purpose of your naming is. Generally, it's a good idea to name the file the same as the class because it makes finding your class a lot easier. If your class is called Foo but you name it Bar.cs then it's going to be harder to find the file in the solution. Generally, it makes sense to try to replicate your namespace structure with folders and your classes in the file name.
|
|
|
|
|
CRobert456 wrote: I have not tried to play with this yet but my feeling is that the file name
could be just arbitrary. Is it correct? Yup, if you generate a GUID and use that as a name, things will work too. Wouldn't be very practical.
It is often yelled that each file should contain a single class, and be named after it. That does lead to a "lot" of files if you stoically do so. There's often some helper-classes that are local to the form, like an inherited EventArgs , or an Enum . If they're really local, they become nested classes within the same file.
Keeps things in a place that is a bit predictable
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Consider generic types with the same name, like Tuple.
You could put
Tuple, Tuple<T>, Tuple<T1, T2> , etc in separate files (Tuple.cs, Tuple`1.cs, Tuple`2.cs), but it's acceptible to put them in one file.
|
|
|
|
|
I have disabled the button on form load. Then I want to enable it when a condition is accomplished, but something's wrong and i can't figure it out what exactly. Conditions are accomplished but button is still disabled.
private void button1_EnabledChanged(object sender, EventArgs e)
{
if (textBox1.Text != "" && textBox2.Text != "" || textBox3.Text != "")
if(ok)
button1.Enabled = true;
}
|
|
|
|
|
You're changing the buttons enabled state in the enable state changed event handler. That doesn't seem right to me. Also, you might want to check your and/or logic in the text box checks.
|
|
|
|
|
So there is no method that I can use it for this? I can enable the button from another function after I check those conditions, but I wanted to do it in this way..
|
|
|
|
|
This looks like WinForms to me. If so, you can use a technique like this[^] to accomplish what you want.
|
|
|
|