Browsing 7239 questions and answers with Jon Skeet

C# changing a value with extension method

If I have the following extension methods: internal static class Extensions { public static void Increase(this uint value) { value += 1; } public static...
Jon Skeet
people
quotationmark

The parameter is being passed by value, that's all. There's nothing special about extension methods on this front. It's equivalent to: Extensions.Increase(i); You'd need the method to have the first parameter passed by reference (with... more 2/2/2016 9:34:06 PM

people

How C# Using Statement Translates to Try Finally

I'm trying to wrap my head around this. According to this page on Using statements: The using statement ensures that Dispose is called even if an exception occurs while you...
Jon Skeet
people
quotationmark

It really does behave like a try/finally - so if the application terminates, the resource may not be disposed... and that's usually okay, because normally disposal is for releasing resources held by the process... and the OS will tidy... more 2/2/2016 7:23:42 PM

people

C# How do I compare and exchange two structs?

I have the following program: public class Program { struct Foo { public int Bar; public int Zoo; } public static void Main() { Foo...
Jon Skeet
people
quotationmark

You can't, basically. The framework doesn't provide a way of performing atomic, lock-free operations on arbitrary structs. more 2/2/2016 5:53:09 PM

people

Can I use C# string interpolation with Linq to SQL

While using EF (up to version 6.1.3 at least) assuming you have a class like this: class Customer { public string FirstName { get; set; } public string LastName {...
Jon Skeet
people
quotationmark

I wouldn't expect so, no. It'll compile down to a string.Format call, which I wouldn't expect to be supported. If you really need the projection to be done in the SQL part, you could test it... but otherwise, as normal, use AsEnumerable()... more 2/2/2016 4:13:25 PM

people

Tuples implementation

Sorry if it's a duplicate. I couldn't find a full explanation on that matter. And the MSDN is vague as usual... Does the .Net tuples provide a usable implementation for equals...
Jon Skeet
people
quotationmark

Looking at the documentation, you can see that: GetHashCode is overridden, although the details are not clearly documented. (It could return 0 for all instances, for example.) Equals is overridden in a well-documented way, delegating to... more 2/2/2016 10:56:42 AM

people

String was not recognized as a valid DateTime (DateTime.Parse("16.10.2014"))

When i Try to convert string to datetime, it thrown an error & it says that String was not recognized as a valid DateTime. My code is below: string dateString =...
Jon Skeet
people
quotationmark

Just use DateTime.ParseExact to specify the format. That's pretty much always the solution when you know the format ahead of time: DateTime date = DateTime.ParseExact( dateString, "dd.MM.yyyy", // This might want to be d.M.yyyy -... more 2/2/2016 7:19:14 AM

people

Java Calendar shows wrong amount of weeks when first week of month is defined as week in which 1 occurs

I've made a function that should get the number of weeks for a given month. For January, May, July and October, it should return 5 weeks. However, it returns 5 for March, June,...
Jon Skeet
people
quotationmark

It sounds to me like you should: Work out the first day of the month Determine from that how many "extra" days are "borrowed" from the previous month (e.g. 0 if day 1 is a Monday; 1 if day 1 is a Tuesday etc) Add that to the number of... more 2/1/2016 1:12:03 PM

people

How to declare byte array dynamically in c# for large files

I am trying to convert a document in a SharePoint document library to byte array in restful WCF service. When I declared the byte array with the maximum size, i am getting the...
Jon Skeet
people
quotationmark

Your buffer doesn't need to be the same size as the file at all. You're only using it as temporary storage, to copy a chunk of the input file into your output MemoryStream. I'd personally use something like 16K as the size - not big... more 2/1/2016 12:59:38 PM

people

java.text.ParseException: Unparseable date: "2016 02 01 10:00pm" (at offset 16)

I want to change change Time format 12 hours to 24 hours. I have a date String like this String date = "2016-02-01"; String time = "10:00pm"; DateFormat df = new...
Jon Skeet
people
quotationmark

I suspect the problem may be that you're not specifying the locale - so it's using your system locale instead, which may have different am/pm specifiers. Here's an example which works for me in desktop Java: import java.util.*; import... more 2/1/2016 6:53:36 AM

people

How to create object of class from client project

When we create a Silverlight application, which includes two projects. The Silverlight project and the web project. I have a class in my SilverlightApplication1.Web namespace and...
Jon Skeet
people
quotationmark

It sounds like your Silverlight project doesn't have a reference to the web project. That's probably a good thing, mind you - I would suggest you set up a third project (as a Silverlight class library) called "Common" or something similar,... more 2/1/2016 6:48:33 AM

people