Browsing 7239 questions and answers with Jon Skeet

Same value other HEX entries in file

I'm running 2 programs that execute the same code : write to a binary file. When the c++ code saves a one byte with value 2 to the file it seems to be binary stored as HEX 02. ...
Jon Skeet
people
quotationmark

You're writing the character '4', '1' or '2' - which is encoded in UTF-16 as 0x00 0x34 (etc). It seems to me that you want to write a short or ushort value or 4, 1, or 2: short lineDepth = 4; if (MaxDev <= 127) { lineDepth = 1; }... more 3/19/2014 1:56:58 PM

people

Convert generic parameter of type T to List<TP> when T is IEnumerable<TP>

My application has a method that caches a value. I need a second method that check if the generic parameter of type T implements IEnumerable and not implements IList. If the...
Jon Skeet
people
quotationmark

Dynamic typing and overloading could help here, if you don't mind using dynamic: object ConvertToListIfNecessary(dynamic input) { return MaybeToList(input); } private IList<T> MaybeToList<T>(IEnumerable<T> input) { ... more 3/19/2014 8:39:18 AM

people

How to dynamically change the visibility of label in mvc3?

I have the following code <div> @Html.LabelFor(m=>m.WrongLogin) </div> I want to display the label dynamically based on a condition from the server side code...
Jon Skeet
people
quotationmark

Just use an if statement: @if (Model.LoginFailed) // Or whatever... { @Html.LabelFor(m => m.WrongLogin); } more 3/19/2014 7:11:31 AM

people

Prepared statement not working when replaced with Statement?

Below is my code where i am using JDBC and to make the query run faster am replacing Statement with PrepareStatement but the page is not woking.what is the wrong i am...
Jon Skeet
people
quotationmark

Yes — your cast will fail (with an exception), and then you're unconditionally calling stmt.close() in the finally block, even though stmt is still null... hence the NullPointerException. Basically, don't do this — use... more 3/19/2014 7:06:43 AM

people

List<integer> c1=new Arraylist<integer>what type object is c1

In collections in java List<Integer> c1=new Arraylist<Integer> Here, c1 is an object of type List which is an interface, and we can't create an object of that...
Jon Skeet
people
quotationmark

The type of the variable c1 is List<Integer>. That just means that the value of c1 at any time has to either be null, or a reference to an object whose type implements List. However, the type of the object that the value of c1... more 3/18/2014 6:47:44 PM

people

difference between bytes returned from reading a file and getbytes from string in Java?

Reading file directly into byte array gives a different output compared to reading data into a String and then getting bytes from it. What is the form for the bytes read directly...
Jon Skeet
people
quotationmark

Reading file directly into byte array gives a different output compared to reading data into a String and then getting bytes from it. Well, it might. And it might not. It depends on how you've read the file as text, and how you've... more 3/18/2014 6:42:39 PM

people

Why comparing a single element against an IEnumerable is not a compilation error

var fooRef = new FooRef(); var fooRefEnumerable = Enumerable.Empty<FooRef>(); var fooRefEquality = (fooRef == fooRefEnumerable); //This compiles without any errors var...
Jon Skeet
people
quotationmark

Why is it comparing a single object and an IEnumerable is valid for RefTypes? Because it's entirely feasible that it will return true: class CunningFooRef : FooRef, IEnumerable<FooRef> { // Implementation... } FooRef... more 3/18/2014 6:34:07 PM

people

Run method in MyRunnable not calling

Why MyThread's run method calls If I pass MyRunnable to create a thread. But If I use Thread class my results are different. below is the code which makes confuse me. Please give...
Jon Skeet
people
quotationmark

Your MyThread.run() method is overriding Thread.run() - and it's the Thread.run() implementation which calls the run method on the Runnable passed into the constructor. As documented: If this thread was constructed using a separate... more 3/18/2014 6:31:11 PM

people

Reflection on internal, overload and with ref parameters method

How to obtain a reference to the method System.Web.Configuration.MachineKey.GetEncodedData using .net v1.1? With the following code it returns null: Type t =...
Jon Skeet
people
quotationmark

Okay, so it sounds like the problem is that there's no equivalent of Type.MakeByRef in .NET 1.1. You may be able to use Type.GetType("System.Int32&") to get that: MethodInfo method = t.GetMethod("GetEncodedData", ... more 3/18/2014 3:38:12 PM

people

Parsing DateTime with timezone offset with JSON.net

I make a call to a web service, which returns an item, one property of which is: "startDate":"/Date(1398859200000+1100)/" In my C# representation, I have: public class MyClass...
Jon Skeet
people
quotationmark

Your expectation is incorrect, basically. The value you've given is 04/30/2014 23:00:00 +11:00 - because it's UTC 04/30/2014T12:00:00 (as verified with Epoch Converter), but with a local offset of +11 hours. So the local time is 11pm. In... more 3/18/2014 3:18:39 PM

people