Browsing 7239 questions and answers with Jon Skeet

Are Portable Class Libraries for Xamarin only?

This is a very basic question. Can Portable Class Libraries be used for simple classes that contain function libraries and no UI components? Is it possible to write a non-UI...
Jon Skeet
people
quotationmark

Can Portable Class Libraries be used for simple classes that contain function libraries and no UI components? Absolutely, although the more modern alternative to PCLs is .NET Core libraries. PCLs had various issues in terms of tooling... more 5/6/2017 3:40:08 PM

people

How to remove time in second after retrieve from database?

i have this label retrieve time from database and display in label. but time in database also consist of second for example 03:45:29, how can i remove the time in second to become...
Jon Skeet
people
quotationmark

Assuming dr is a SqlDataReader or similar, you probably want to cast to DateTime, then format the value appropriately: DateTime dateTime = (DateTime) dr[3]; string formatted = dateTime.ToString("yyyy-MM-dd HH:mm",... more 5/5/2017 7:56:23 AM

people

What's the Noda Time 2.0 equivalent of MapTimeZoneId?

I have been using the following code without flaw for a while now: internal static string WindowsToIana(string windowsZoneId) { if (windowsZoneId.Equals("UTC",...
Jon Skeet
people
quotationmark

Currently, you need the same code that exists within the gut of Noda Time, but it's not very much: internal static string WindowsToIana(string windowsZoneId) { // Avoid UTC being mapped to Etc/GMT, which is the mapping in CLDR if... more 5/5/2017 6:12:47 AM

people

Do we get any benefit from adding null check if we are already using catch all Exception handler?

This is specific to .NET I am writing a code piece where I have to use catch all exception handler. I call a series of function which may return null. I do not want to continue if...
Jon Skeet
people
quotationmark

Yes, I would strongly advise using null checks: It shows that you expect that the values can be null, and that that in itself is not a problem If you ever add logging in your catch block, you can easily do so without being spammed by... more 5/5/2017 5:54:18 AM

people

How can I convert a .NET Core project to a .NET Framework project?

I created a "Console App (.NET Core)" project in Visual Studio. Now I need to add a dependency that only works on .NET Framework 4.6+, not .NET Core. Is there a way to convert my...
Jon Skeet
people
quotationmark

If you're happy with it still using the new tooling, the easiest approach is probably just to edit the project file (csproj). Right-click on the project in Solution Explorer and you should have a context menu option of "Edit... more 5/4/2017 4:16:51 PM

people

When reading stream, why not stop iterating when 0 bytes read

The standard idiom when reading from a stream is to check for EOF (-1): while((bytesRead = inputStream.read(buffer)) != -1) This seems pretty standard - I checked source for...
Jon Skeet
people
quotationmark

Basically because it would be pointless. Look at the documentation: If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the... more 5/4/2017 2:31:23 PM

people

Why does Asia/Dubai timezone abbreviation differ between timezonedb and tzdata?

I'm using php timezonedb 2017.2. How come it returns +04 instead of GST for Asia/Dubai timezone? While default built in php tzdata returns GST. $dt = new DateTime('now', new...
Jon Skeet
people
quotationmark

Basically, because time zone data changes over time. It sounds like timezonedb is up-to-date, but tzdataisn't. This change was made in the 2017a release of the IANA time zone data. From the announcement email - emphasis mine: Changes... more 5/4/2017 12:44:35 PM

people

Find a date from a specific list of date

I am a beginner in c # and I can not find the solution for my problem. I am creating a personal project that allows me to send reminders, I have a date list and I need to do...
Jon Skeet
people
quotationmark

I'd suggest using List<T>.BinarySearch: that will find the index of the date. If the index is 0 or more, then the exact date was found. If it's negative, then taking ~index will get you the index where the date would have been... more 5/4/2017 8:44:17 AM

people

How to increase ReadTimeout in Google HTTP Client

I have my application running in GAE. This application makes REST call to my CloudML. Here is the code for that GoogleCredential credential =...
Jon Skeet
people
quotationmark

I haven't tried this, but I'd expect you to be able to effectively chain the request initializers together: final GoogleCredential credential = ...; HttpTransport httpTransport =... more 5/3/2017 9:47:53 AM

people

How does java.util.Map's getOrDefault() works?

I noticed that if I do map.getOrDefault("key1", new Object()), even if object is present for key1 in the map, new Object() is created. Though it is not returned by the method but...
Jon Skeet
people
quotationmark

Shouldn't the default object be created only if it is not there in the map ? How could that be the case? This call: map.getOrDefault("1", new Empl("dumnba")) is equivalent to: String arg0 = "1"; Empl arg1 = new... more 5/2/2017 11:47:51 AM

people