Browsing 7239 questions and answers with Jon Skeet

Implicit type cast not working for method parameters?

Consider the following code snippet: class TypeCast{ public static void main(String[] args){ byte by = 4; //compiler casts int literal to byte doCasting(4); ...
Jon Skeet
people
quotationmark

This is the difference between an assignment context (JLS 5.2) and an invocation context (JLS 5.3) for conversions. Assignment context conversions include: In addition, if the expression is a constant expression (ยง15.28) of type byte,... more 2/9/2015 8:14:45 AM

people

Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<DAL.HRM_PersonalInformations>'

I am trying to Get some data from Database and Bind them in Drop-Down list.. But getting following error : - public virtual...
Jon Skeet
people
quotationmark

Well, in your projection you have: c => new {FullName = (c.FirstName + ' ' + c.LastName), c.EID} That's creating an instance of an anonymous typoe - not an instance of HRM_PersonalInformations. If those are the only two properties... more 2/9/2015 6:47:09 AM

people

How to parse a angular ui dateTime string to c# datetime

I know a lot of questions about this has been answered. I have tried for about 3 hours with no luck. I am using angular-ui datetime picker, the format is ...
Jon Skeet
people
quotationmark

Look at the format you're passing: "yyyy-MM-dd'T'HH:mm:ss'Z'" That has no milliseconds, whereas your sample is "2015-02-08T06:00:00.000Z" which does have milliseconds. It looks like you want: "yyyy-MM-dd'T'HH:mm:ss.fff'Z'" Also, I'd... more 2/8/2015 9:25:17 PM

people

How does `foreach` iterate through a 2D array?

I was curious as to how a foreach loop in C# iterates over a multidimensional array. In the following code, the second nested for loop was originally a foreach which would give...
Jon Skeet
people
quotationmark

I was curious as to how a foreach loop in C# iterates over a multidimensional array. As always for questions like this, the ultimate authority is the C# language specification. In this case, section 8.8.4: The order in which... more 2/7/2015 6:32:16 PM

people

Java input date from Scanner in one line

I'm trying to read date from a user to pass to GregorianCalendar variable. Currently I have an awkward setup, where it reads line by line. Can you help with a solution that...
Jon Skeet
people
quotationmark

I would suggest you read in a line of text, with a specific format, then use DateFormat to parse it. For example: DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm", ... more 2/7/2015 5:27:16 PM

people

c# escaping chars trying to run command

I'm trying to run this command with several quotation marks: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --proxy-server="10.10.10.10:9999"...
Jon Skeet
people
quotationmark

You need to separate the binary to run from the arguments. I would recommend using ProcessStartInfo to make this clearer: var info = new ProcessStartInfo { FileName = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", ... more 2/7/2015 4:58:41 PM

people

Enter array without knowing it's size

Is there a way to make an array in java, without defining or asking for it's length first ? A.k.a the user enters some numbers as arguments, and the program creates an array with...
Jon Skeet
people
quotationmark

Is there a way to make an array in java, without defining or asking for it's length first ? A.k.a the user enters some numbers as arguments, and the program creates an array with that many arguments. It's unclear exactly what... more 2/7/2015 12:14:40 PM

people

"The specified type member 'Date' is not supported in LINQ "

_dbEntities.EmployeeAttendances.Where(x => x.DailyDate.Date.Equals(DateTime.Now.Date)).ToList(); "The specified type member 'Date' is not supported in LINQ to Entities....
Jon Skeet
people
quotationmark

If the DailyDate property is already just a date, instead of a date and time, then it would be simplest to just use: // Outside the query so it becomes a constant, effectively var today = DateTime.Today; var employees =... more 2/7/2015 10:57:11 AM

people

Convert Object in C# to JSON with Attributes

I am trying to convert an object like the one below: public class MyObject { public ListOfStuff[] item { get; set; } public string Name { get; set; } public string...
Jon Skeet
people
quotationmark

You just need to use the [JsonProperty] attribute to specify the JSON name. Here's an example (ignoring ListOfStuff for simplicity - apply the same approach): using System; using Newtonsoft.Json; public class MyObject { ... more 2/7/2015 10:46:10 AM

people

Is there a way to find out a DateTime variable corresponding calendar?

Suppose we have a given DateTime variable something like : DateTime BirthDate{get;set;} and different users/clients set this variable according to their preferred calendar (in...
Jon Skeet
people
quotationmark

No, DateTime doesn't retain calendar information... it's effectively always in the Gregorian calendar. If you construct a DateTime with a different calendar system, it converts it to the Gregorian calendar, and you need to use the Calendar... more 2/7/2015 10:38:00 AM

people