Tag Info

Hot answers tagged

44

Multiply by 1041204193. When the result of a multiplication doesn't fit in an int, you won't get the exact result, but you will get a number equivalent to the exact result modulo 2**32. That means that if the number you multiplied by was coprime to 2**32 (which just means it has to be odd), you can multiply by its multiplicative inverse to get your number ...


9

No, It Isn't Duck Typing I would argue that this is not an acceptable form of duck typing in a static language. In a language that supports duck typing, one would expect to be able to define a function that accepts an object foo of unspecified type that defines a function (or property) bar. def call_bar (foo) { foo.bar } The function doesn't care what ...


8

Defining the property as you've shown is the same as defining methods int GetProperty() and void SetProperty(int i). Properties are powerful short-hand in C#. A property does not implicitly create a private field in C#. That is the default implementation of an auto-property, for example public string MyString { get; set;} - however, a property which defines ...


6

Knowing how to develop good software is way more important than the specific programming language you know. I'm talking about concepts such as testing, design, reviewing, requirements gathering, et cetera. You can pick up a new programming language in a few weeks, but these concepts stay the same. For a good list of concepts, see this post on BlogOverflow: ...


6

This maybe better suited as an question to Math (sic) SE. You are basically dealing with modular arithmetic, since dropping the left-most bits is the same thing. I am not as good at Maths as the people who are on Math (sic) SE, but i will try to answer. What we have here is that the number is being multiplied by 33 (3*11), and its only common denominator ...


3

I would store this next to your authentication. If you are using OAuth 2.0 Tokens for example you could add an Claim where you set the customerId. If you are using cookie based authentication I would set the customerId inside a cookie and resolve it every request. This way you don't keep any state on your server, but always have the CustomerId available. ...


3

RAII doesn't necessarily mean you have a fully working object. It means you have a fully constructed object that is ready to work. So if your object needs an initialisation call to set its state, that's fine - its nothing to do with RAII that ensures you have an object that is possible to fill with state (ie its not half-built in some uncertain state). I ...


3

Properties are methods! A backing field will be added to the class which implements the interface (either manually or through an auto-property).


3

I see three reasons 1) As jimwise says, they can be changed without recompiling. If they are actually used as enum values in application (do something if it equals that), only usefull thing to change without recommpiling is their name. 2) they CAN contain more than name and id, but two cannot have same id unlike C# style enums 3) they can be used in ...


2

No it isn't. Objects of a particular class all support exactly the same set of messages no matter what constructor they were created with. Overloading constructors merely means that it isn't necessary to initialize explicitly all the fields that make up an object's state. For instance, an object might have color with a sensible default value, so you can ...


2

One way to get it is to use brute force. Sorry I don't know C# but the following is c-like pseudo code to illustrate the solution: for (x=0; x<=INT_MAX; x++) { if (x*33 == test_value) { printf("%d\n", x); } } Technically, what you need is x*33%(INT_MAX+1) == test_value but integer overflow will automatically do the % operation for you ...


1

I think if you randomly interviewed 10,000 developers, ~30% would be on Java on windows for development; ~30% on dotnet - c#, vb.net etc and others on android client apps or php, python, ruby, objective c server apps etc on windows and ububtu, linux for development and production. So choose 1 - C# or Java or vb.net ... and stick with it. There are ...


1

The only goal of GC.SuppressFinalize is: to prevent the finalizer from releasing unmanaged resources that have already been freed by the IDisposable.Dispose implementation. Source: MSDN Once you disposed the object, you should indeed call GC.SuppressFinalize(this);, like shown in an answer to the question "When should I use GC.SuppressFinalize()?". ...


1

You could the SMT solver Z3 to ask it to give you a satisfying assignment for the formula x * 33 = valueFromFile. It will invert that equation for you and give you all possible values of x. Z3 supports exact bitvector arithmetic including multiplication. public static void InvertMultiplication() { int multiplicationResult = new ...


1

The main benefit I see is that you can add new enum values with a database operation, without compiling and deploying a new version of your application. By treating the set of "Foos" which may exist as data, the impact on the running application of adding new types of "Foo" is kept small.


1

I'd say your best bet is to create some sort of pattern for either each mod, or a dictionary of all known patterns, and use that to parse each version. For mod1, Local: rv0-stable-10 Online: rv1-alpha-13, the pattern will be complicated. It looks like you'll need to first parse rvX- as a number, the middle part perhaps as an enum, and the last as a number ...


1

It's fair to say that overloaded constructors specify different ways to construct a duck. That's not duck typing, though. Consider the following class: public class Rectangle { public Rectangle(Point A, Point B) { // Constructs a rectangle by using points A and B as a diagonal, // and filling in the rectangle with the usual lines ...


1

Forms are objects, so you can pass them into the constructor of each other form: Class Form2{ Form form1; Form Form2(Form form1){ // Constructor this.form1 = form1; } } Now, you have a reference to the Form1 object in a field of Form2. If you need information, you use Form1.information


1

Both patterns have different purposes and you may want to have one, the other or both depending on your needs: Tasks are things that can be awaited. You can do something after the task is done. Events are things that notify you of something. You can do something while the task is running. In the past, events were also used to notify people when the task ...


1

MoveNext() is a method that is called over and over and every time it has to move to the next item. This means you can't implement it by simply using a for loop (unless you use yield return, which is pretty much the reason why yield return exists), you need to rewrite it so that each MoveNext() call executes just part of that loop. Specifically, it would ...


1

maybe you want a collector that regularly runs and when it does, it cleans up these .. how can we call them.. I know - 'garbage' objects. We can call this thing a garbage collector. Dispose was added to provide deterministic finalisation so you can have objects clean up immediately rather than waiting for later, making a non-deterministic Dispose is just ...


1

You might take a look at Microsoft's ScheduledDisposable. I've never used it, but it looks as though it will queue your objects for disposal on a separate thread. But if a pool is what you're looking for, I think this will work: public interface IDisposableWrapper<TDisposable> : IDisposable where TDisposable : class, IDisposable { TDisposable ...


1

There are several issues that need to be resolved. Categories The usual use of categories is to identify classes or groups of records. If you create reports, having the values kept in a category table makes it easy for report generators or external data warehouses to properly categorize items. Control Flavors Very often, the values control the operation ...



Only top voted, non community-wiki answers of a minimum length are eligible