Browsing 7239 questions and answers with Jon Skeet

(MVC C#)Advice on my Maintenance Scheduling system with Maintenance Records

I have this maintenance scheduling system, and in im using MVC C# Entity Framework, I have this table Truck Table that has - truck id, registration no., kilometer run reading,...
Jon Skeet
people
quotationmark

It looks like this is just a matter of getting the ID out of the truck - after all, your oddly-named AddJobOrder variable is presumably of type Truck or something similar. I suspect you just need something like: truck_no =... more 9/3/2015 6:08:23 AM

people

No operator found which takes a right hand operand of type 'B' (or there is no acceptable conversion)

I have the following piece of code. I'm trying to print the sum of two objects ints but the compiler gives me the following error: binary '<<' : No operator found which...
Jon Skeet
people
quotationmark

The a + b expression is using your custom operator - so it's as if you'd written (module constness - I'm just trying to get the flavour of what's going on): B c = a + b; cout << c; That doesn't work because the compiler can't find... more 9/3/2015 6:03:50 AM

people

Assigning a value to a dynamic type using reflection and bypassing the object cast\box that GetValue returns

I have two objects that have exactly the same properties. Here's an example: public class Field<T> { public T Value {get;set;} // more things } public class...
Jon Skeet
people
quotationmark

The problem is that the binder will use the static type of the value you're trying to assign to the property - whereas you want to do this dynamically. All you need to do is change the variables to be of type dynamic and it works: dynamic... more 9/1/2015 4:40:48 PM

people

Deferred execution again: Local instance of Random inside LINQ query/queries

I wish to understand the following behaviour I stumbled across today. This small program showcases the "problem": class Bar { public int ID { get; set; } } class Foo { ...
Jon Skeet
people
quotationmark

The problem is that you're testing against different IDs each time you evaluate the predicate. You don't need foos at all for this. You can just have: var bar = bars.First(b => b.ID == rng.Next(5) + 1); That will execute the... more 9/1/2015 3:07:18 PM

people

C# Reflection Get value of unknown field

I am trying to use reflection to call a method with some arguments but I have some difficulties to use the correct setup. Here what I've done. // The method I am trying to...
Jon Skeet
people
quotationmark

Type.GetField(string) only returns public fields. I suspect you want: FieldInfo fieldInfo = editorGUIType.GetField( "s_RecycledEditor", BindingFlags.NonPublic | BindingFlags.Static); more 9/1/2015 1:28:30 PM

people

Why won't abs() in java work?

I have always had a question about java.lang.Math: (It might by very basic) Why do I have to Math.abs(-100) and can't to abs(-100)? I figure that Math is a class. And abs is a...
Jon Skeet
people
quotationmark

You can import all the methods in Math: import static java.lang.Math.*; or just the one method you want: import static java.lang.Math.abs; Normal imports just import classes, making that class available via its short name. more 9/1/2015 1:14:37 PM

people

How to manage exception in catch block c#?

I have following code. try { int s=10; int k=0; int stdsd = s / k; } catch (DivideByZeroException ext) { FileStream fs = new FileStream(@"C:\temp\data.txt",...
Jon Skeet
people
quotationmark

You can't handle the exception generated from one catch block in a catch block associated with the same try/catch statement. Instead, you need an extra one: catch (DivideByZeroException ext) { try { FileStream fs = new... more 9/1/2015 8:46:20 AM

people

Is there any chance that getDayOfMonth() from org.joda.time.DateTime to return 0 as the first day of the month?

Let's have an example: We introduce 01.03.2013 in an input field. And then in a method we check for this: 0==dateTime.getDayOfMonth() are there any chances for this to be true?...
Jon Skeet
people
quotationmark

I suspect it's feasible for a custom Chronology to return 0, but none of the "built-in" chronologies will do so, and certainly the common Gregorian/ISO chronologies won't. In other words, you'd only need to worry about this if you're... more 9/1/2015 8:37:51 AM

people

Java Pass By Value and reference

I have the following code. I can't, however, understand it's behavior about pass by value and reference. class Dog{ String name; int x=100; Dog(String name){ ...
Jon Skeet
people
quotationmark

You're incrementing x twice, but on different dogs. Look at this code: public static void foo(Dog d) { ++d.x; d = new Dog("Taz"); ++d.x; } Initially, d refers to the dog with a name of Tom, with x=100. That isn't a copy of... more 9/1/2015 6:09:35 AM

people

Why isn't OleDbCommand and OleDbType.Date not working, and no error?

Sorry for the rather lame question... But here is my dilemma... I'm trying to reduce repetitive code as much as possible here, since I have several similar queries, that just...
Jon Skeet
people
quotationmark

You've got quotes round most of your parameters in the SQL, which means the other parameters won't be where you expect them to be. Your SQL should be: UPDATE Loads SET Customer=?, FinishTime=?, Carrier=?, Reference=?, Tags=?,... more 9/1/2015 6:00:12 AM

people