Browsing 7239 questions and answers with Jon Skeet

System.currentTimeMills Execution time

we are using one web service which works usually in 30-40 ms time.Inside that web service we are calling System.currentTimeMills for 38 times for calculating the time taken in...
Jon Skeet
people
quotationmark

Yes, it's absolutely feasible to call it hundreds of thousands of times in that period. It doesn't have a huge amount of overhead - but it's not what you should be calling for time measurement anyway. Use System.nanoTime() instead, which... more 2/15/2014 6:54:03 PM

people

Fluent Interface How to hide members (property setters) if they are already set?

I am taking a stab at writing a fluent API in C#. What I am trying to do is make a builder that can set some properties. The properties can be set in any order, and all of them...
Jon Skeet
people
quotationmark

My question is - how can I make my optional properties disappear from intellisense after they are set without creating a huge number of interfaces that grow exponentially with the number of properties? You can't with your current... more 2/15/2014 11:48:04 AM

people

Add query to linq var

I never used this before. I need to add another member to the query. How can I add "link" to "source"? var titles = regexTitles.Matches(pageContent).Cast<Match>(); var...
Jon Skeet
people
quotationmark

It sounds like you just need another call to Zip. The first call will pair up the titles and dates, and the second call will pair up the title/date pairs with the links: var source = titles.Zip(dates, (t, d) => new { t, d }) ... more 2/15/2014 9:02:48 AM

people

Comparing two dates minutes in sql server

What I'm trying to do is comparing a DateTime variable and a date inside a table in sql server if the the differece between those two date are less than 30 min the select query...
Jon Skeet
people
quotationmark

Firstly, stop building your SQL dynamically like that. Use parameterized SQL instead. Next, I think you just want DATEADD. If you know that LOGIN_DATE will always be in the past, you just need to add 30 minutes to that, and check that the... more 2/15/2014 8:25:52 AM

people

deferred iteration of IEnumerable<T>?

Trying to build a asp.net mvc html helper for creating a bootstrap table. I've defined my fluent interface as follows: public interface IBootstrapObject: IHtmlString { ...
Jon Skeet
people
quotationmark

You don't need to access it as an IEnumerable<T>. You can just use the non-generic IEnumerable: var properties = _modelType.GetProperties(); // Or whatever... remove indexers etc foreach (object item in _dataSet) { foreach (var... more 2/15/2014 8:10:55 AM

people

Lifetime of the object

In some block creates an anonymous object and the object in the "weak link": //first object System.Random string result = new Random().Next(0,1) == 1 ? "equal 1":"sory, but not...
Jon Skeet
people
quotationmark

Well in the second example, it's hypothetically possible for the Random instance to be immediately collected after the WeakReference constructor completes and before the Target property is accessed - there's no strong reference to it at... more 2/14/2014 5:15:33 PM

people

How to change value of an object using linq

I have the following statment that if isdefault is true to this collection i need to set each object isDefault property to false. custHead.lstCustomziation.Where(x =>...
Jon Skeet
people
quotationmark

LINQ is for querying. You should use a foreach loop to make changes: foreach (var item in custHead.lstCustomziation.Where(x => x.IsDefaultSelected)) { item.IsDefaultSelected = false; } That said, if IsDefaultSelected is false for... more 2/14/2014 2:30:14 PM

people

Insert Anonymous object in a list of same anonymous type

I am creating a anonymous type list using LINQ, and later binding it with a ComboBox. But I want to add an empty item in that list, but its not working. XNamespace ns =...
Jon Skeet
people
quotationmark

I strongly suspect this builds but doesn't show the extra item. That's because you're adding the new item to a "temporary" list that you throw away, and then you're building a new list for the data source. You want to call ToList() just... more 2/14/2014 2:26:03 PM

people

how do I get data between two dates

I would like to get data between two years, so from 1st of Jan to 1st of Jan, This is what i have done: public list<a>method(){ DateTime d= new...
Jon Skeet
people
quotationmark

If you just want "the next year" it's simple: // Note: more descriptive variable names than "d" and "dd" int thisYear = DateTime.Now.Year; // Note this is in the local time zone... DateTime thisYearStart = new DateTime(thisYear, 1,... more 2/14/2014 9:58:23 AM

people

Inheritance code returns no value

I created a super class called Employee, with a subclass called ProductionWorker and a driver called ProductionWorkerDriver. The program takes my entered info and returns the...
Jon Skeet
people
quotationmark

You're not doing anything with the data you've entered: System.out.println("Shift 1 or 2:"); shift = keyboard.nextInt(); System.out.println("Pay Rate:"); payRate = keyboard.nextDouble(); ... the shift and payRate variables aren't used... more 2/13/2014 11:10:27 PM

people