You searched for jon skeet. We found 71 results in 0.054 seconds.

What did I miss to send a http part post request

I am trying to send an image using http multipart request (later I will add another image) I did this: HttpClient client = HttpClientBuilder.create().build(); HttpPost...
Jon Skeet
people
quotationmark

Look at when you're calling execute - that's before you build the request properly! Just reorder your code so that you fully build the request, then you post it to get a response, then you use the response. (I'd also be personally... more

people

How to make async method generic over Task type

My question is on the surface very similar to Using a generic type as a return type of an async method. However, he did not have a real world usage scenario and so all that could...
Jon Skeet
people
quotationmark

No, async just doesn't support that. The simplest option to fake it would be: public static async Task<T> Retry<T>(Func<Task<T>> action) { for (var i = 0; ; i++) { try { return... more

people

Separate functions into validation and implementation? Why?

I was reading a C# book in which the author (some dude named Jon Skeet) implements a Where function like public static IEnumerable<T> Where<T> ( this...
Jon Skeet
people
quotationmark

The reason is that the iterator block is always lazy. Unless you call GetEnumerator() and then MoveNext(), the code in the method won't get executed. In other words, consider this call to your "equivalent" method: var ignored =... more

people

Why does LINQ to XML not escape characters like '\x1A'?

I get exception if in XElement's content I include characters such as '\x1A', '\x1B', '\x1C', '\x1D', '\x1E' or '\x1F'. using System; using System.Collections.Generic; using...
Jon Skeet
people
quotationmark

Most of those characters simply aren't valid in XML 1.0 at all. Personally I wish that LINQ to XML would fail to produce a document that later it wouldn't be able to parse, but basically you should avoid them. I would also recommend... more

people

Casting a generic class. (cast) vs Class.cast()

I have searched for my use case and found some interesting answers but they are not as suitable as i need. What would the appropriate way to do...
Jon Skeet
people
quotationmark

I think that both methods do the same. No, they don't. Because at execution time, the first code doesn't know the type of T due to type erasure. That means the cast basically does nothing within the method. The calling code might... more

people

Proto2 vs. Proto3 in C#

I have to send messages to another team using the proto2 version of Google Protocol Buffers. They are using Java and C++ on Linux. I'm using C# on Windows. Jon Skeet's...
Jon Skeet
people
quotationmark

If the other team has any required fields and you send messages to them without specifying those fields (or even explicitly specifying the default value, for primitives) then the other end will fail to receive the messages - they won't... more

people

Limitation of generics in C#2

I'm currently reading Jon skeet's amazing book "C# in depth (3d version)". I'm stuck on p.99 dealing with lack of contravariance for generics. class TestGenericVariance { ...
Jon Skeet
people
quotationmark

The idea is that you make AreaComparer generic like this: public class AreaComparer<T> : IComparer<T> where T : IShape { public int Compare(T x, T y) { return x.Area.CompareTo(y.Area); } } Then when you... more

people

C# for loop and post increment

I'm having a hard time understanding why the following loop prints 0 on each iteration. for (int i = 0, j = 0; i < 10; i++) { Console.WriteLine(j += j++); } Shouldn't...
Jon Skeet
people
quotationmark

Shouldn't the value of j increase after each iteration? Nope. Your loop body is somewhat equivalent to this: int tmp1 = j; // Evaluate LHS of += int tmp2 = j; // Result of j++ is the value *before* the increment j++; j = tmp1 +... more

people

cannot access class in the same package without adding to classpath

Project structure: ./src/com/example/Test.java ./src/com/example/Dog.java Test.java package com.example; public class Test { public void testing() { Dog d = new...
Jon Skeet
people
quotationmark

The compiler will treat directories on the classpath as source root directories - in other words, when trying to find classes for package com.example, it will look for both class and source files in a com/example subdirectory from each... more

people

How to efficiently ensure a decimal value has at least N decimal places

I want to efficiently ensure a decimal value has at least N (=3 in the example below) places, prior to doing arithmetic operations. Obviouly I could format with...
Jon Skeet
people
quotationmark

If you're nervous that the compiler will optimize out the operator (although I doubt that it would ever do so) you could just call the Add method directly. Note that you don't need to add and then subtract - you can just add 0.000m. So for... more

people