Browsing 7239 questions and answers with Jon Skeet

Back and forth calculation of integer Identifier using bit shifting and OR operations

Good morning, don't know if this question is hitting the right StackExchange network. If not please forgive me. I got an decimal/integer identifier value which i need to split...
Jon Skeet
people
quotationmark

Just mask and shift. You've already got a comment describing the format: // Message identifiers are constructed: // Unit Type Bit 8-10 // Board ID Bit 5-7 // Unit Specific Message Ids Bit... more 3/11/2015 6:59:53 AM

people

Randomize two List<string> in C# in same order

I have two string lists en and en1 List<string> en = new List<string>(new string[] { "horse", "cat", "dog", "milk", "honey"}); List<string> en1 = new...
Jon Skeet
people
quotationmark

Two obvious ways: Take a normal shuffle method, and change it to modify both lists at the same time Transform the two lists into a single joint list, shuffle that, then split them again The second sounds cleaner to me. You'd use... more 3/10/2015 8:55:21 PM

people

Method inside method c# (Xamarin)

i am using a google guide to create place suggestions in my Android app made with Xamarin. I was wondering how would you convert this Java code to c#, and how to deal with the...
Jon Skeet
people
quotationmark

Just create a new named class extending or implementing Filter (depending on whether it's an interface or a class). Make it a nested class if you don't need it elsewhere. For single-method interfaces, normally a delegate is the simplest... more 3/10/2015 6:43:54 PM

people

Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#2>' to 'System.Linq.IQueryable<WhiteBoardApp.Models.BrokerOutright>

I have an issue returning some data in my application using the following C# code [Queryable(AllowedQueryOptions =...
Jon Skeet
people
quotationmark

Yes, because you're projecting to an anonymous type: .Select(x => new { x.Id, x.Product, x.Term }) It sounds like you want to use an object initializer for the BrokerOutright type: .Select(x => new BrokerOutright { ... more 3/10/2015 5:54:43 PM

people

How to test method with 'out' parameter(s)?

I am trying to write a unit test for a method that has out parameters. My method specifically is a TryParse method for my custom object. I am using .NET 4.5/5 with Visual Studio...
Jon Skeet
people
quotationmark

Personally, I'd use InternalsVisibleTo in order to make the method visible to your test code, but if you do want to use PrivateType, I'd expect you to be able to just create an object[] which you keep a reference to, pass it into... more 3/10/2015 5:35:17 PM

people

Short Time with DateTime.ParseExact

I’m trying to parse a time. I’ve seen this question asked/answered here many times but not for this specific scenario. Here’s my code: var time1 = DateTime.ParseExact("919",...
Jon Skeet
people
quotationmark

I'm not sure there is any format that can handle this. The problem is that "H" can be either one digit or two, so if there are two digits available, it will grab both - in this case parsing it as hour 91, which is clearly... more 3/10/2015 2:21:30 PM

people

Property name in getter/setter

I am creating some properties and came across a scenario I haven't seen before. Consider private double _temperature; private double _maxTemp; public double Temperature { ...
Jon Skeet
people
quotationmark

If you mean in terms of IsTempTooHigh, that's fine (although the condition is the wrong way round for the name). It's entirely valid to refer to one property within another, although you need to be careful that you don't make it recursive.... more 3/10/2015 2:07:15 PM

people

How razor convert byte[8] to string?

In my table there is a column with datatype of timestamp. Using entity framework I can get the value of this timestamp value and it's a byte[] value. Once this value is sent to...
Jon Skeet
people
quotationmark

What's the encoding method used by the razor? Well that just looks like Base64 to me: byte[] x = {0, 0, 0, 0, 0, 1, 159, 44}; Console.WriteLine(Convert.ToBase64String(x)); Output: AAAAAAABnyw= You can go the other way with... more 3/10/2015 12:29:55 PM

people

filling values in array

what i want to do is fill the empty aray kyo[] with the add() method but it keeps getting an error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 ...
Jon Skeet
people
quotationmark

An empty array can never have any content. Once an array has been created, its size is fixed - you can change the content of the elements, but you can't change how many elements it has. See the Java arrays tutorial for more... more 3/10/2015 12:13:34 PM

people

What is the difference of using TemporalAmount or TemporalUnit in Java 8?

I write some piece of code in Java 8 which use time arithmetic. I realize that I can implement in differentways. Lets look at simple code below. Of course it is the same result...
Jon Skeet
people
quotationmark

Duration can only handle fixed-length periods, such as "hours", "minutes", "seconds", "days" (where it assumes exactly 24 hours per day). You can't use "months" with Duration, because a month varies in length. Period - the other common... more 3/10/2015 12:05:11 PM

people