Browsing 7239 questions and answers with Jon Skeet

Best way to replace two first characters of String from every line JAVA

I have a text file with about 3 million lines and I need to replace the first two characters of every line with "". My current code is String[] lines = content.split("\n"); ...
Jon Skeet
people
quotationmark

Is there a faster way of doing this? Yes - don't perform repeated string concatenation. That's the part that's killing your performance. Use a StringBuilder instead. It's also not even doing what you want it to - you're not using the... more 7/31/2014 11:57:46 AM

people

How to store BIG int values

What would you use if you had to hold numbers bigger than the ulong type can hold (0 to 18,446,744,073,709,551,615)? For instance measuring distance between planets or galaxies?
Jon Skeet
people
quotationmark

For values which only require up to 28 digits, you can use System.Decimal. The way it's designed, you don't encounter the scaling issue you do with double, where for large numbers the gap between two adjacent numbers is bigger than 1.... more 7/31/2014 9:05:11 AM

people

Exception not catching when using Custom Exception classes in ASP.NET MVC and C#

I have created few custom exception class public class CreateNewUserWebException : Exception { public CreateNewUserWebException(string email): base( ...
Jon Skeet
people
quotationmark

The part you've highlighted in the debugger is the inner exception. That isn't used by the CLR to determine which catch block to enter. The outer exception is just a DbUpdateException - which you haven't specified a particular catch block... more 7/31/2014 5:47:41 AM

people

How is "return (from tbl in context.[tablename] select tbl)" executed if calling method then does a .Where() on result?

A method returns the IQueryable<T> result of a from x in context.y select x query. The calling method then calls .Where( a => ...) on that resultset. Is the entirety...
Jon Skeet
people
quotationmark

If the method returns an IQueryable<T>, that's returning the query - not the results of the query. So calling Where will construct another query, applying a filter to the original query... still using expression trees. So when you... more 7/30/2014 8:19:01 PM

people

May I call 2 constructors with different arguments in the another constructor

I need to call a constructor 2 times in the another constructor. For example: public class SpinnerUtilityAssociationComparison extends SpinnerUtilityBase { static String...
Jon Skeet
people
quotationmark

So how i can achieve this. You can't, basically - not the way you're trying. Each constructor chains to exactly one other constructor, either in the same class or the direct superclass. I suggest you create one "primary" constructor... more 7/30/2014 12:57:51 PM

people

How to find all methods that are declared as virtual in c# using reflection?

For example public class UserInfo {} public interface IUser { UserInfo Get(int id); string GetData(int id); } public class User : IUser { public UserInfo Get(int id) ...
Jon Skeet
people
quotationmark

The problem is Get is a virtual method in that it implements IUser.Get and so is called using execution-time dispatch - I suspect, anyway. (You haven't given us a complete program, so I've had to guess.) If you actually want "methods that... more 7/30/2014 10:54:28 AM

people

SQL injection vulnerability thru preparedStatement

An Statement like this String query = "SELECT * FROM users WHERE userid ='"+ userid + "'" + " AND password='" + password + "'"; Statement stmt =...
Jon Skeet
people
quotationmark

The exact way in which this protects you is up to the database, but there are two obvious options: The database driver could perform string interpolation and generate a SQL statement which ensures that all parameters are properly... more 7/29/2014 9:04:31 PM

people

Long to decimal with decimal point at a specific position

In C#, I have a long that I need to convert to a decimal. The problem is that I want to put the decimal point at a specific position in the long. For example, let's say I have...
Jon Skeet
people
quotationmark

You could use the Decimal constructor that takes different constituent parts. You'll need to do a bit of bitshifting to get the exponent into all the relevant sections, but that shouldn't be too hard. If you know that your value won't be... more 7/29/2014 5:48:06 PM

people

Why does my second variable value change when updating the first?

I have a Form with two Datalog class variables public partial class ModifyDataForm : Form { public DataLog DLog; private DataLog copyCurrent; public...
Jon Skeet
people
quotationmark

The value of copyCurrent doesn't change. The data within the object that copyCurrent refers to may change, but that's a different matter. Suppose you give two separate people (Alice and Bob) pieces of paper with your home address written... more 7/29/2014 5:29:47 PM

people

Noda: Find out if in daylight saving

How do I find out if my current local time is adjusted by Daylight Savings or not. Basically the equivalent of DateTime.Now.IsDaylightSavingTime() in NodaTime I saw this, but...
Jon Skeet
people
quotationmark

Lasse's answer is correct, but it can be made simpler: From v1.3 you can use ZonedDateTime.IsDaylightSavingTime: var zone = ...; var now = ..; var daylight = now.InZone(zone).IsDaylightSavingTime(); And from v2.0 (unreleased at the... more 7/29/2014 1:30:15 PM

people