Browsing 15528 questions and answers with Jon Skeet

C# 7 Expression Bodied Constructors

In C# 7, how do I write an Expression Bodied Constructor like this using 2 parameters. public Person(string name, int age) { Name = name; Age = age; }
Jon Skeet
people
quotationmark

You don't, basically. Expression-bodied members are only available when you have a single statement to execute. You have two in this case. I mean, you could use tuples, but I strongly advise against it: // DO NOT USE THIS CODE - IT'S... more 2/1/2017 7:27:29 AM

people

Adding and subtracting Period from LocalDate doesn't produce the same date

i use java 8 LocalDate and Period classes to add and remove years, months and days. Why in some cases if add Period to date and remove the same period java 8 return another...
Jon Skeet
people
quotationmark

Why in some cases if add Period to date and remove the sane period java 8 return another date? Because that's how calendrical arithmetic works - months are uneven lengths, and it makes things tricky to say the least. You're adding... more 1/30/2017 9:33:26 PM

people

Why does this non blocking IO call fail?

Background I'd like to send a large (30MB, but could be much larger in the future) amount of data using Java's non-blocking SocketChannel Why non-blocking? So that the...
Jon Skeet
people
quotationmark

I believe the answer lies in the WritableByteChannel.write documentation: Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state,... more 1/30/2017 12:29:48 PM

people

Class Access Modifiers internal

I have created a class called ClientCapsule which contains data about the client, this class contains another class i created in the same scope called ClientInformation . i don't...
Jon Skeet
people
quotationmark

It sounds like you need ClientInformation to be a public class - just give it an internal constructor, preventing instantiation from elsewhere. more 1/26/2017 10:03:59 PM

people

Scope of members inside using statement

I'm confused by the following code and the scope of using statement and its object disposal. using(DbFactory db = new DbFactory()) { Repository repo = new...
Jon Skeet
people
quotationmark

The scope of the repo variable (in your first case) is the using statement. You can't refer to it outside the using statement, because it's declared in there. We can't tell the scope of the result variable because you haven't shown its... more 1/25/2017 6:01:12 PM

people

Why does (boolean ^ int > 0) work?

When you try to do something like this: if (true ^ 1) { //do something } the compiler reasonably says that operator ^ is not defined for argument types boolean and int. But...
Jon Skeet
people
quotationmark

It's simple: > has higher precedence than ^, so if (true ^ 1 > 0) { is equivalent to if (true ^ (1 > 0)) { which is equivalent to if (true ^ true) ... which is just logical XOR. I would never write code like this, mind... more 1/25/2017 2:55:27 PM

people

HttpWebRequest not posting

As per the question, I POST json to http but I'm not getting any output when I use GET. I'm trying to POST json then close the stream. I do not need to care about the reply. To...
Jon Skeet
people
quotationmark

You're never asking for a response, so it's not making the request. Just add: using (var response = request.GetResponse()) { // Use the response } Note that your "get" code isn't exception-safe - it should use using statements... more 1/25/2017 9:12:51 AM

people

Unexpected type error Simple hangman code

I'm building a very simple hangman game. where it takes in a word to be guessed then takes in letters as guesses. But i am getting an unexpected type error. The error is occuring...
Jon Skeet
people
quotationmark

The left-hand side of an assignment has to be a variable - you've got a method call. Note that strings are immutable, so assuming you were trying to change the content of secret, you can't. You might want to create a char[] from secret,... more 1/24/2017 3:18:13 PM

people

dotnet restore unable to resolve Telerik.UI.for.AspNet on macOS

I'm trying to get a dotnet project working on macOS but I'm getting stuck when I run dotnet restore. All packages install fine except for my Telerik package: Unable to resolve...
Jon Skeet
people
quotationmark

Well that's not the name of a Nuget package any more, as far as I can tell. I believe you want the KendoUICore. Based on the versions of that - which include 2016.3.1118 - I suspect that temporarily had the name... more 1/24/2017 8:20:56 AM

people

UTF 8 not working in live server

I am new to docx4j. I am creating new .docx file using docx4j. My code works perfectly while deploying project from eclipse to tomcat server. But it does not work on live server....
Jon Skeet
people
quotationmark

I suspect this may be the problem: afiPart.setBinaryData(html.getBytes()); That will use the platform-default encoding - which could clearly differ between your local machine and your server. I would strongly encourage you to always... more 1/23/2017 11:13:26 AM

people