Browsing 7239 questions and answers with Jon Skeet

NLog use Persian Calendar Date format

I am interested in using NLog in my C# project and found it great, but In my country Clients works with "Persian Calendar". As you know Microsoft developed a library to support...
Jon Skeet
people
quotationmark

There are two difficulties with this: You'd need to work out how the formatting is performed in both of these cases, and see how you can customize it, e.g. by specifying a different culture or a formatting delegate The Persian calendar... more 11/6/2014 7:41:07 AM

people

How to add to a BigDecimal

I have the following function that itterates over an array, calls a method on each 'Refund' object that returns a BigDecimal that contains some value e.g. 20.45: private String...
Jon Skeet
people
quotationmark

You need to use the return value of add, because BigDecimal is immutable. So you want: total = total.add(refund.getAmountPayable()); (Personally I think this would have been more obvious if the method had been called plus rather than... more 11/6/2014 7:06:15 AM

people

NetworkStream of TcpClient does not receive each package

I have a part of code about Send and Receive use Network stream. I send two packages thought socket but Receive method receive one package and it contains two packages . I don't...
Jon Skeet
people
quotationmark

TCP is a stream protocol. You don't send "packages" - you send a stream of data, and receive a stream of data. The fact that the data is broken up into packets behind the scenes is a low-level implementation detail of the NetworkStream... more 11/5/2014 5:51:53 PM

people

Why can't generic types have explicit layout?

If one tries to make a generic struct with the [StructLayout(LayoutKind.Explicit)] attribute, using the struct generates an exception at runtime: System.TypeLoadException:...
Jon Skeet
people
quotationmark

It's specified in ECMA 335 (CLI), partition II, section II.10.1.2: explicit: The layout of the fields is explicitly provided (§II.10.7). However, a generic type shall not have explicit layout. You can imagine how it could be awkward... more 11/4/2014 10:29:22 PM

people

Java: How can I get the size of Integer(object) array?

I'm talking about Integer object data type, not primitive int Suppose this: Integer[] arr = new Integer[5]; arr[0] = 2; arr[1] = 2; arr[2] = 3; Then the array...
Jon Skeet
people
quotationmark

Same way as for any other array - you use the length field: int length = arr.length; // 5 From the JLS section 10.7: The members of an array type are all of the following: The public final field length, which contains the... more 11/4/2014 7:13:15 PM

people

Stacking namespaces can't be referenced just like any other element?

So here is a snippet I made where one namespace in inside another (B is inside A). Usually when you use 'using SpaceA;' you can access all elements without typing SpaceA. This is...
Jon Skeet
people
quotationmark

Usually when you use 'using SpaceA;' you can access all elements without typing SpaceA. Only the direct types which are members of SpaceA. A namespace-or-type-name is never resolved using a namespace in a normal using directive and... more 11/4/2014 6:59:07 PM

people

Delegate in C# attribute

I am looking to put a static delegate inside of a custom attribute. What I am running into is Activator.CreateInstance is a major bottle neck and I'd like to avoid it. I am using...
Jon Skeet
people
quotationmark

Sounds like you want Delegate.CreateDelegate. Specify the method name and the type, find the method with reflection (once) and then create a delegate from it. You could potentially do that within the attribute constructor, although I... more 11/4/2014 6:15:57 PM

people

Why deadlock is occuring intermittently in my code?

Below code I have written for a deadlock, but for small "for loop" code is not falling in deadlock while when I keep "for loop" till 10 then deadlock is occurring. Can someone...
Jon Skeet
people
quotationmark

You're only going to get a deadlock if one of your threads obtains one monitor and the other thread obtains the other monitor before the first thread obtains the second monitor. The more threads you have obtaining the monitors on the two... more 11/4/2014 5:32:54 PM

people

Convert xml to custom class using lambda linq

Attempting to parse an xml document to a custom class which I have created. I have successfully figured out how to parse the document, but for some reason I am having to do it...
Jon Skeet
people
quotationmark

It sounds like all you need is a call to First() or Single() or whatever - to say that you only want one result (the first or only result - other options are available): Ping ping =... more 11/4/2014 5:05:18 PM

people

LINQ's deferred execution, but how?

This must be something really simple. But i'm going to ask it anyway, because i think that others will also struggle with it. Why does following simple LINQ query is not executed...
Jon Skeet
people
quotationmark

The difference is that you're changing the value of the input variable, rather than the contents of the object that the variable refers to... so digits still refers to the original collection. Compare that with this... more 11/4/2014 3:48:38 PM

people