Browsing 7239 questions and answers with Jon Skeet

How to find the total redundancy in the numerical list

If I have a list List<int> mylist = new List<int>(); mylist.Add(15); mylist.Add(15); mylist.Add(10); mylist.Add(10); mylist.Add(10); If you want Count() which is...
Jon Skeet
people
quotationmark

It sounds like you probably just want to use LINQ: int target = 10; // Or whatever int count = myList.Count(x => x == target); more 4/22/2016 3:45:48 PM

people

PHP strtotime timezone

i have problem with PHP strtotime converting to different timezone. My code is simple: <?php date_default_timezone_set("Europe/Bratislava"); echo date("H:i",strtotime("20:00...
Jon Skeet
people
quotationmark

This code is returning: 02:00. But it should return 14:00. No, it's right. You're converting from 8pm in New York (currently UTC-4 due to DST) into the Europe/Bratislava time zone (currently UTC+2 due to DST). So: New York: ... more 4/22/2016 12:20:17 PM

people

MySql.Data.MySqlClient.MySqlException : Incorrect datetime value

Hai I have to add details from one table to another which should be within to dates. These dates are read from text boxes. But i'm getting Error: "An exception of type...
Jon Skeet
people
quotationmark

Basically, the problem is how you're passing parameters into the database. You shouldn't need to create a MySqlDateTime yourself - just use parameterized SQL and it should be fine: // TODO: Use a date/time control instead of parsing text... more 4/22/2016 5:42:21 AM

people

Is it possible to avoid creating java.sql.Date Object in For Loop

While Inserting Date into mysql , i have the following code DateFormat format_date = new SimpleDateFormat("yy-mm-dd"); for (Stocker s : symbol_set) { insert_stmt.setString(1,...
Jon Skeet
people
quotationmark

It really depends on the implementation of PreparedStatement.setDate() and addBatch(). If those methods clone all the relevant data appropriately, you could create a single instance of java.sql.Date outside the loop, then call setTime on... more 4/21/2016 1:13:41 PM

people

Round java.util.Date to end of day

I want to round a java.util.Date object to the end of the day, e.g. rounding 2016-04-21T10:28:18.109Z to 2016-04-22T00:00:00.000Z. I saw Java Date rounding, but wasn't able to...
Jon Skeet
people
quotationmark

Given the documentation of DateUtils, I'm not sure I'd trust it with this. Assuming you're only interested in a UTC day, you can take advantage of the fact that the Unix epoch is on a date boundary: public static Date roundUpUtcDate(Date... more 4/21/2016 10:55:42 AM

people

Inheritance behavior issue

I m create a class and i m inherit class public class abc : Manager, Inteface { public abc() { string a = context; } } When i m inherit class first and interface only then...
Jon Skeet
people
quotationmark

That's simply invalid C#, and the compiler should be telling you about it - the class that you're deriving from should appear first in the list. As an example of the compiler error message you should be getting: public interface IFoo... more 4/21/2016 5:39:01 AM

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 4/20/2016 11:54:22 AM

people

Call method without instance C#

I'm using c#. I have class class A { public void MyMethod(int x){//Do something...}; } How can I call MyMethod without creating an instance of Class A? Can I use...
Jon Skeet
people
quotationmark

You can do this... but you really, really shouldn't: // DO NOT USE THIS CODE using System; public class Evil { public void Method() { Console.WriteLine($"Is this null? {this == null}"); } } class Test { ... more 4/20/2016 9:44:18 AM

people

Create a time Offset from string with NodaTime

I have a string that represents the offset of a particular customer. An example is UTC+1:00. It is always the offset relative to UTC, so the string will always start with UTC...
Jon Skeet
people
quotationmark

It sounds like you want: var pattern = OffsetPattern.CreateWithInvariantCulture("'UTC'+H:mm"); var offset = pattern.Parse(text).Value; more 4/19/2016 7:10:28 PM

people

XDocument: Could not find file 'C:\Program Files (x86)\IIS Express\myfile

Here's my code Dim doc = XDocument.Load("Web.sitemap") I'm trying to load the an XML file so that I can manipulate it. I'm getting an error saying that file cannot be found in...
Jon Skeet
people
quotationmark

I'm getting an error saying that file cannot be found in the IIS Express directory. Yes, because you're loading it with a relative path name, which means "relative to the current working directory"... which in this case is IIS. You... more 4/19/2016 7:07:56 PM

people