Browsing 15711 questions and answers with Jon Skeet

Difference between associative and commutative

I am trying to understand associative in monoid. From the book, it says: Associativity simply says that you can associate the arguments of your operation differently and...
Jon Skeet
people
quotationmark

Take string concatenation as an example. Suppose you're using a language which uses + for string concatenation. That's naturally associative, as the grouping doesn't matter: ("a" + "b") + "c" == "abc" "a" + ("b" + "c") == "abc" But the... more 6/26/2017 12:18:44 PM

people

empty get in expression bodied syntax?

Is it possible to write this property: string Error { get; } in expression bodied syntax (=>), for example: string Title { get { return title; ...
Jon Skeet
people
quotationmark

No, because this: string Error { get; } ... is an automatically-implemented property. The compiler is generating a field for you behind the scenes, but you can't refer to that field within the code. If you need to use the backing field,... more 6/26/2017 9:43:53 AM

people

Why UTC (which is not a time zone) is considered as a time zone in Java (and not only there)?

Given that UTC is not a time zone, but a time standard (as stated, for example, here), why in my Java application I can use UTC as if it was a time zone (see the code snippet...
Jon Skeet
people
quotationmark

Because it makes life much, much simpler to regard UTC as a time zone than to treat it as something else, basically. It's one of those "Yeah, strictly speaking it's not" scenarios. For everything except "Which region of the world is this... more 6/26/2017 9:18:21 AM

people

Why is variable not printing correctly?

Why did the following program output Method B 0 instead of Method B 200? I can't understand what my problem is. class A{ int a=100; void myMethod(){ ...
Jon Skeet
people
quotationmark

Instance field initializers run after the superclass constructor has been called. So the order of execution is: Call to new B() Start to initialize instance of B: Implicitly call super() Start to initialize the instance with respect to... more 6/26/2017 5:04:13 AM

people

Sending large image through TCPClient c#

I have the following code to send a picture to a receiving application public static void sendFile(string file, string ip) { using (TcpClient client = new...
Jon Skeet
people
quotationmark

You're only calling Read once, which certainly isn't guaranteed to read all the bytes. You could either loop, calling Read and copying the relevant number of bytes on each iteration, or you could use Stream.CopyTo: var imageStream = new... more 6/25/2017 1:36:45 PM

people

Scope of a variable cfr. Pluralsight C# test

I'm preparing for my microsoft exam about c# 70-483, "still a long way to go" and following the C# path on pluralsight. After doing the test and review my incorrect answers i came...
Jon Skeet
people
quotationmark

The question is vague and badly worded IMO. There's no such concept as a variable "going out of scope" in C# - but there is the scope of a variable, and the scope of the i variable is the whole of the foreach loop body, including the empty... more 6/24/2017 8:04:29 AM

people

How do I sort list of numeric strings without parsing?

I have a list of strings with high values (greater than int 32), How do i sort them in ascending order without parsing? List =...
Jon Skeet
people
quotationmark

Firstly, I almost certainly wouldn't take the approach below. I'd either convert the input to a List<long>, or just use the code you've already got, at least until I'd absolutely proved that it wasn't good enough. However, as this... more 6/23/2017 5:28:23 PM

people

Removing Duplicate Nodes from Xml using C#

I have an xml like <xml> <Test> <TestData> <TestData> <Name>Alex</Name> </TestData> </TestData> </Test> ...
Jon Skeet
people
quotationmark

LINQ to XML makes this reasonably easy if some assumptions are met: There are no elements with "triple duplication" e.g. <TestData><TestData><TestData>. I'm sure it's feasible to work around that, but it's trickier. We... more 6/23/2017 4:04:33 PM

people

Array.equal() giving wrong output

To my understanding, the following code should print true, since both elements are equal. From java docs Array.get() will return: Returns the value of the indexed component...
Jon Skeet
people
quotationmark

This has nothing to do with arrays really. Your comparison is equivalent to: Object x = Integer.valueOf(3); Object y = Byte.valueOf((byte) 3); boolean equal = x.equals(y); That's never going to return true. Even though your original... more 6/23/2017 2:01:15 PM

people

Generic types and ienumerable<T>, where to start

I want to pass in a dataset to a function but it could be different each time (but will always implement IEnumerable. So my call to the function will be: var items = new...
Jon Skeet
people
quotationmark

You're trying to use T as a type argument, so the compiler needs to know which T you mean. Chances are you want to make your method a generic method too. Fixing the name to follow conventions (and be more readable in general) at the same... more 6/22/2017 10:17:19 AM

people