Browsing 7239 questions and answers with Jon Skeet

Override Sealed is valid but why not Virtual Sealed in C#?

The below code snippet is valid public class BaseClass { public virtual void Display() { Console.WriteLine("Virtual method"); } } public class DerivedClass :...
Jon Skeet
people
quotationmark

override sealed is valid because it says "I'm overriding a base class method, but derived classes can't override me." That makes sense. One part of it is talking about the relationship to its base class; the other is talking about the... more 2/4/2015 6:54:25 AM

people

AsEnumerable with range of dates

with my code below I'm able to select row .field ("Objectif) values based on current week and current year from datatable(dt1). how can I do the same by putting a range of date as...
Jon Skeet
people
quotationmark

Well you can use < and > with DateTime values, so you can do something like: Dim lowerBound As DateTime = ... Dim upperBound As DateTime = ... ... in the query ... Where lowerBound <= Row.Field(Of DateTime)("date") AndAlso ... more 2/3/2015 5:42:22 PM

people

C# Lists reference with two?

I need 2 lists which are separate and one list containing the items of these two lists. List<int> list1 = new List<int>(); List<int> list2 = new...
Jon Skeet
people
quotationmark

No, you can't do that with List<T> directly. However, you could declare: IEnumerable<int> union = list1.Union(list2); Now that will be lazily evaluated - every time you iterate over union, it will return every integer which... more 2/3/2015 5:19:18 PM

people

information loss from long to float in Java

if you call the following method of Java void processIt(long a) { float b = a; /*do I have loss here*/ } do I have information loss when I assign the long variable to the...
Jon Skeet
people
quotationmark

Do I have information loss when I assign the long variable to the float variable? Potentially, yes. That should be fairly clear from the fact that long has 64 bits of information, whereas float has only 32. More specifically, as... more 2/3/2015 5:03:44 PM

people

Is it possible to perform Method Hiding without using New keyword?

Today I had an interview where I have been asked Is it possible to perform Method Hiding without using New keyword? As far as I know , it is not possible. So I said...
Jon Skeet
people
quotationmark

Absolutely - if you don't specify anything, you still get the same effect as with the new modifier, but you get a warning as well. There's also explicit interface implementation, of course. In both cases, just casting the target to a... more 2/3/2015 4:09:31 PM

people

Parsing String Timestamp as JODA TimeStamp

Given the following UTC time: 2009-11-17 10:45:32 How can I create an org.jode.time.LocalDateTime with that exact time, but in UTC? In other words, that time-stamp represents a...
Jon Skeet
people
quotationmark

I suspect the problem here is just the lack of a T in the value. Note that the idea of "a LocalDateTime [...] but in UTC" is meaningless. A LocalDateTime value has no time zone. The simplest fix is probably just to create a... more 2/3/2015 3:24:25 PM

people

Parsing xml string in windows phone 8

I have the following xml string: <AssumeRoleWithWebIdentityResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/"> <AssumeRoleWithWebIdentityResult> ...
Jon Skeet
people
quotationmark

You've made two mistakes: There's no AssumeRoleWithWebIdentityResponse element under the root element; it is the root element The AssumeRoleWithWebIdentityResponse element is in a namespace (https://sts.amazonaws.com/doc/2011-06-15/") so... more 2/3/2015 2:49:59 PM

people

Change the date part of a DateTime property before database record created

I have a view model in which I am storing a DateTime but in my view using a JQUERY datetimepicker, time only: ViewModel [DataType(DataType.Time)] public DateTime? MondayFrom {...
Jon Skeet
people
quotationmark

Just use the TimeOfDay property to extract the time within the day, and add that to the date you want: private static readonly DateTime BaseDate = new DateTime(1900, 1, 1); var updatedDateTime = BaseDate + otherDateTime.TimeOfDay; You... more 2/3/2015 2:45:57 PM

people

c# override [] bracket array allocator

I want to override this operator and I can't find how to do it. I want to, wherever an array of a specific class is going to be initialized to run a c++ code, since that class is...
Jon Skeet
people
quotationmark

I want to, wherever an array of a specific class is going to be initialized to run a c++ code, since that class is wrapped. No, you can't do that. The array will always be an array of references to instances of the class, always... more 2/3/2015 2:23:36 PM

people

port sha 1 hash from C# to Android/java

I need to port the following code from C# private string hashcode(string code) { byte[] bytes = Encoding.Unicode.GetBytes(code); byte[] inArray =...
Jon Skeet
people
quotationmark

This is the C# code you've got for converting the userCode string to bytes: byte[] bytes = Encoding.Unicode.GetBytes(code); And the Java code is just: userCode.getBytes() That means in Java you're using the platform-default encoding,... more 2/3/2015 1:52:54 PM

people