Browsing 7239 questions and answers with Jon Skeet

Is Calendar.get(Calendar.DAY_OF_WEEK) impacted by Calendar.getFirstDayOfWeek()?

Maybe a stupid question, but I have a question I didn't find in the Java documentation. Does the value of Calendar.get(Calendar.DAY_OF_WEEK) change based on any value change of...
Jon Skeet
people
quotationmark

Does the value of Calendar.get(Calendar.DAY_OF_WEEK) change based on any value change of Calendar.getFirstDayOfWeek() No. Sunday is Sunday (Calendar.SUNDAY), regardless of whether that's the first day of the week, the second or the... more 8/9/2015 5:28:21 PM

people

Character array insertion in postgresql using Npgsql

I would like to insert an array of strings into a table in PostgreSQL using Npgsql in C#. I have written the code below but am getting an...
Jon Skeet
people
quotationmark

You're calling AddWithValue, but not providing the value - you're providing the type. Additionally, you're not providing an array - you're just providing a single string. I suspect you just want: command.Parameters.Add("@participants",... more 8/8/2015 8:50:51 AM

people

How to use object retrieved from method

I made a method to create a polygon with hexagonal shape and retrieve it as an object but I don't know how to use said object. The code is as follows: public object...
Jon Skeet
people
quotationmark

Your method is declared to return object - but you know it's a Polygon, so assuming you want callers to rely on it returning a Polygon (which seems reasonable) you should change the return type. public Polygon Hexagon() You also need to... more 8/8/2015 7:01:11 AM

people

Converting Generic List of object to defined collection class with Lambda and C#

This is an issue I have seen in two different jobs that use a 3-tier structure and haven't found a clean way around it. This also applies to using LINQ statements I believe. I...
Jon Skeet
people
quotationmark

No, there isn't. ToList creates a List<T> - and there's no way of casting a plain List<T> to a TestObjectCollection without creating a new TestObjectCollection. Personally I'd avoid creating a collection deriving from... more 8/7/2015 2:38:34 PM

people

Where is body of PropertyChanged?

I'm wondering where is the body(instance) of PropertyChanged ? private int age; public int Age { get { return age; } set { age =...
Jon Skeet
people
quotationmark

This is a field-like event. It's a bit like an automatically-implemented property - the C# compiler provides the implementation. (I'd prefer it if the syntax were more like automatically implemented properties, but that's a different... more 8/7/2015 2:02:18 PM

people

Java: can java.lang.Character be used for characters outside Basic Multilingual Plane?

As I understand java keeps string in uft16 which for every code points uses either 16 (for BMP) or 32 bits. But I am not sure if class Character can be used for keeping code point...
Jon Skeet
people
quotationmark

No, char and Character can't represent a code point outside the BMP. There's no specific type for this, but all the Java APIs just use int to refer to code points specifically as opposed to UTF-16 code units. If you look at all the... more 8/7/2015 12:50:29 PM

people

How do you divide a time period into equal intervals and find the current one?

I need to schedule a periodic job for lots of users. This job will run at a fixed rate, the interval. I want to distribute the execution of the job for each user uniformly over...
Jon Skeet
people
quotationmark

Assuming you're actually interested in instants and durations (i.e. nothing to do with periods, dates, time zones etc) then your code should be fine. I'd actually go into milliseconds earlier in this case... the maths is all simple... more 8/7/2015 11:59:04 AM

people

Can't reference a method property

I'm trying to call a function NextPrevious((List<Store>)model.Group.ToList(), 3, groupPage.Value, ref next, ref previous); With the method definition being.. private...
Jon Skeet
people
quotationmark

A List<Group> is not a List<Store>. However, you can use a type argument to the ToList method to make it create a List<Store> instead: NextPrevious(model.Group.ToList<Store>(), ...) That's assuming you're using... more 8/7/2015 11:40:25 AM

people

How to run Roslyn instead csc.exe from command line?

After installing VS 2015, running csc.exe from command line causes this message to be displayed to console: This compiler is provided as part of the Microsoft (R) .NET...
Jon Skeet
people
quotationmark

It sounds like your path is inappropriate, basically. If you open the "Developer Command Prompt for VS2015" you should have $ProgramFiles(x86)$\MSBuild\14.0\bin early in your path - and the csc.exe in there is Roslyn. I suspect you're... more 8/7/2015 10:54:06 AM

people

Real example of Func<sometype> + Func<sometype>

Lets say you have: Func<string> a = () => "string here"; Func<string> b = () => "other string here"; var c = a + b; What the realworld need for this?
Jon Skeet
people
quotationmark

The only time I can think of it being useful is if you're actually going to treat it as a list of delegates (via Delegate.GetInvocationList), and invoke each one separately. You could do that for validators, for example - where each... more 8/7/2015 10:13:41 AM

people