Browsing 7239 questions and answers with Jon Skeet

Simple Age Calculator base on date of birth in C#

I have created a simple age calculator. I want to remove decimal places but the problem is when I substract now to bday. example : I input 2012, 10 and 23 and the date now is...
Jon Skeet
people
quotationmark

Contrary to the comments, TimeSpan does not help you here, because a year is not a fixed length of time. That in turn leads to your expressed aim being very strange indeed. You really shouldn't be representing a date as a fractional number... more 10/22/2014 9:25:15 AM

people

IList.Select() that returns an IList (without copying)

I have a method with an IList<T> parameter. It's IList and not IEnumerable, because the method needs quick random access and most entries will not be queried at all (the...
Jon Skeet
people
quotationmark

No, there's nothing within the framework that does this as far as I'm aware. Your second option seems sensible to me. You'll need to make it read-only, throwing appropriate exceptions for the mutating operations of IList<T>. One... more 10/22/2014 8:46:28 AM

people

List(T).ForEach is not defined using Xamarin

I got some code from a friend of mine and it works great in a windows. forms application. When I try to use the same Code in a Xamarin.Forms project, it...
Jon Skeet
people
quotationmark

You're using the Portable Class Library subset of .NET; that doesn't include List<T>.ForEach. Personally I'm not keen on this approach anyway - it would be much more readable IMO to use LINQ to select the right company. After all,... more 10/22/2014 8:41:00 AM

people

How does Linux handle DST (daylight saving time?

How does linux handle daylight saving time (DST) Does the swich happen instantly, like 3'o clock swiched instantly to 2'o clock ? or it changes slowly I ask you this becouse i...
Jon Skeet
people
quotationmark

I ask you this becouse i have large date base on my servers and if this swich happens instantly one hour on entryes in the data base will pe owerwritten That suggests you're writing the local time into the database. Regardless of how... more 10/22/2014 8:33:26 AM

people

Cannot implicitly convert type 'System.Collections.Generic.List< >' to 'System.Collections.Generic.IList< >'

There are lots of possible duplicates for this post.But i tried most of thems, unfortunately my error still happens. Error is : Error 1 Cannot implicitly convert type...
Jon Skeet
people
quotationmark

Assuming InvoiceMaster derives from or implements InvoiceHD, and that you're using C# 4 and .NET 4 or higher, you can just use generic variance: return MstDtl.ToList<InvoiceHD>(); This uses the fact that an... more 10/22/2014 6:18:32 AM

people

combine two xml_docs C# xmlDocument

I have been using the following SO, How to merge two XmlDocuments in C#, to try and merge two sample xml files into one. Essentially here are my two xml files test1.xml:...
Jon Skeet
people
quotationmark

It's not entirely clear what merge operations you need to perform - but if you just need to copy the root node's child elements, that's really simple with LINQ to XML: XDocument doc1 = XDocument.Load("test1.xml"); XDocument doc2 =... more 10/22/2014 6:08:52 AM

people

I am borrowing a method that catches 10 kinds of exceptions but does nothing with them. Can I replace them with just (Exception e)

Im borrowing this method I found on the internet: private static int getExifOrientation(String src) throws IOException { int orientation = 1; try { /* *...
Jon Skeet
people
quotationmark

To sum up: does "catch Exception e" catch all kinds of exceptions or should each one be named individually It catches everything of type Exception or a subclass. It will not catch other Throwables, e.g. Error. But given that all the... more 10/21/2014 4:55:14 PM

people

understanding nested locks in java

i want to understand this: String string; public Test(String string){ this.string = string; ..... } public void foo(newObjectPerCall o) { synchronized (o) { ...
Jon Skeet
people
quotationmark

if one thread acquire the inner lock, other threads that acquired the outer lock, will remains inside the foo function? Yes. They will block, waiting to acquire the monitor for string. When on thread ,for some reasons, remains... more 10/21/2014 4:45:08 PM

people

Why am I receiving a "call is ambigious" error when trying to user Math.Floor with an integer?

I've just made a small program that uses the Floor method: public static void Main(string[] args) { int i; decimal[] t = new decimal[30]; for(i=0;...
Jon Skeet
people
quotationmark

Could someone explain me what's wrong? The compiler is telling you exactly what's wrong - the call is ambiguous. The fact that you're trying to use the result of the call to assign into a decimal array is irrelevant to the compiler -... more 10/21/2014 10:51:44 AM

people

Get Month of out System Datetime

I have data in my database that contains the following filed. Id | name | RegDate 1 John 2014-09-05 2 mike 2014-09-05 3 Duke 2014-10-14 I'm performing a query to...
Jon Skeet
people
quotationmark

I would strongly recommend that you get rid of all the string manipulation. Your query doesn't conceptually have anything to do with strings, so why are you introducing them into the code? You can write your query as: int currentMonth =... more 10/21/2014 10:33:58 AM

people