|
It depends what it overflows from. For example if you add 1 to 2147483647 you will get -2147483648.
|
|
|
|
|
Wow it really works as the counters we have in cars that counts kilometers? They start all over again from the beginning, only for integers we also have negative ones
|
|
|
|
|
Exoskeletor wrote: Wow it really works as the counters we have in cars that counts kilometers? Ehr.. no.
Just look up how a PC stores numbers in binary, and the limitations of each number-"type".
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
There was a time i new all those things in university but years have passed since, ok i have look them up
|
|
|
|
|
That is absolutely false. Your 99.99 percent isn't worth much, you haven't understood how integers typically work. Think again, and if necessary: experiment, observe, but stop guessing and "being sure".
Here are three questions for you, first think about them; the answer is simple when you reason correctly. If you can't solve it, then try it, and search the explanation:
1. we all expect n! to be larger than (n-1)! and yet, with your original implementation this is not true for n=14, the value isn't larger, it is about 33% less!!!
2. multiplying positive numbers cannot ever yield a negative, and yet your code will claim 19! to be negative (no, not -1).
3. And finally, why is 34! the first one that returns zero...
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
|
|
|
|
|
Overflow could cause positive + positive to be negative and the other way around from what i have read.
|
|
|
|
|
Certainly - and you would have an overflow exception as well. Unless you deliberately overlook it.
If you don't specify any handling, but some default handler is called, it depends on this handler where execution continues. Maybe the storing of the (overflowed) result is skipped. If the sum variable was initially zero it may still be zero, if nothing is stored.
Then: A factorial is never negative. So is it appropriate handle it as signed value at all? (You may still have an overflow, but if you ignore it, you have a true wraparound effect, like your car odometer)
|
|
|
|
|
can you say it 10 more times :P i think it will help
|
|
|
|
|
I am able to load a block on to a form when I click a button (the button is on the form) but I want to move my code so that when the form loads the block on the form will also load. Where would I put the code?
///
Graphics gs = this.CreateGraphics();
Pen p = new Pen(new SolidBrush(Color.Red));
gs.DrawRectangle(p, Goal);
|
|
|
|
|
Brian_TheLion wrote: I want to move my code so that when the form loads the block on the form will also load. Unclear what you are doing here:
1. you can add, or remove, the Paint EventHandler for any Form in code ... to draw on the Form.
2. the standard Load EventHandler you define is called automatically when the Form is shown.
If you create new Forms at run-time, you can install a Paint EventHandler once you have a valid reference to the new Form.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Don't just draw the block like that - partly because it'll disappear when you minimize the form or drag another form over the top, and partly because you need to Dispose of all Graphics contexts you create as soon as you are finished with them. The best way of doing that is via a using block:
using (Graphics gs = this.CreateGraphics())
{
using (Brush b = new SolidBrush(Color.Red))
{
using (Pen p = new Pen(b))
{
gs.DrawRectangle(p, Goal);
...
}
}
...
} Note that that also applies to Pens, Brushes, and other Graphics elements.
If you want to draw on your form, then handle the Form.Paint event and use the graphics context provided:
private void FrmMain_Paint(object sender, PaintEventArgs e)
{
using (Brush b = new SolidBrush(Color.Red))
{
using (Pen p = new Pen(b))
{
e.Graphics.DrawRectangle(p, Goal);
}
}
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks Griff.
I'll try what you suggested.
|
|
|
|
|
Use the Paint handler, it is the only place where drawing ever should occur.
Avoid calling CreateGraphics , it is an expensive operation. The Paint handler gives its Graphics for free, see the PaintEventArgs that comes with it.
For all those small but disposable objects (Pens, Brushes, Fonts, ...) consider NOT creating them all the time by either:
- using the pre-existing ones, e.g. Pens.Red , Brushes.Red , etc.
(and since you didn't create those, you are not supposed to dispose of them either);
- creating your own, possibly more specialized ones (e.g. a thicker Pen) but then create them only once and keep them alive in class variables; when doing so, there is no need to dispose of them when your program exits.
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
|
|
|
|
|
|
Can you give me an example please
|
|
|
|
|
When using NET.Framework I can't find anyway of dragging objects to a form (eg textbox, button).
When using NET.Core I can't find anyway of displaying the form so I can place objects on the form. All I get is the code for the form.
Has there been some major changes to version 8.0 of C# which prevents me from doing certain things, such as dragging objects such as a button on to a form?
|
|
|
|
|
You need to provide more information. When are you doing this, where are the objects being dragged from etc.? What part of the C# language do you believe is affecting this?
|
|
|
|
|
On older version of c#. I could display the form on the screen and on the left side of the screen I had a list of tools such as button, textbox. I could then select an object from the list then drag it on the form and position it on the form where I wanted the object to appear (when I say object I mean things like buttons and textboxs).
In C# 8.0 I don't seem to be able to do this unless you know of a way or something in the setup I need to change first.
|
|
|
|
|
It is impossible to guess what you are doing. Please edit your original question above and add full details of the problem, including the failing code.
|
|
|
|
|
If you're talking about designing the from in Visual Studio, you can get the ToolBox to show up from the View menu. Just click the View menu, then Toolbox.
Or you could hit Ctrl-W, X.
|
|
|
|
|
Hi Dave.
I tried clicking on Toolbox in the View menu but when I do that the only thing I see on the screen is a list of tools. I need to have both the form and the list of tools displayed on the screen at the same time.
In past versions of C# things were put in panels on the screen so the form display was put in one panel in the middle of the screen and the list of tools was put in the left side panel.
Can panels be setup with C# 8.0 like they have been in the past for the user interface?
|
|
|
|
|
Then you double-click the form you want to open.
The Toolbox doesn't have a maximize button so it cannot be taking up the entire window. There is a small pushpin icon next to the Close (X) button in the ToolBox window. That can pin the toolbox window or allow it to autohide into a tab on the left edge of the Visual Studio window.
|
|
|
|
|
Thanks Dave.
I found I had to dock some things such as toolbox so the interface becomes panels and is the way I want things to appear.
Brian
|
|
|
|
|
I think, and I may be wrong but is winforms supported in NET.Core? I believe the visual designer may not be included yet.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
In that case I'll need to use only Net.Framework
|
|
|
|