Browsing 7239 questions and answers with Jon Skeet

What is this thingy called in .net?

I remember a while back, I was working on a web page based on C# razor. There was a response property that served as a kind of pipeline between the controller and the page. I...
Jon Skeet
people
quotationmark

I think you're looking for the ViewBag. The ViewBag property enables you to dynamically share values from the controller to the view. It is a dynamic object which means it has no pre-defined properties. You define the properties you... more 8/4/2015 6:29:50 PM

people

Should Count() of an IEnumerable be avoided?

In general, I am using a List and then returning them as IEnumerable when I no longer need to update them. However, I ran into an issue where I actually need to enumerate through...
Jon Skeet
people
quotationmark

Will IEnumerable enumerate every item and find the count (O(N)), or will it rely on List's Count property (O(1))? It will use the Count property. Basically the implementation checks whether or not the object implements... more 8/4/2015 5:43:35 PM

people

Prevent Daylight saving for "java.util.TimeZone"

I am trying to schedule a reminder email that has to be sent on first Tuesday of August and November. When I do that, the time of remainder email for November is changing from...
Jon Skeet
people
quotationmark

If you want a fixed-offset time zone, just use SimpleTimeZone: TimeZone tz = new SimpleTimeZone(TimeUnit.SECONDS.toMillis(-420), "id"); more 8/4/2015 5:40:19 PM

people

Testing equality of two instances of a class when they are typed as their base class and subclass?

Lets say I have a high level interface IRobot public interface IRobot { Boolean DoAction(object action); } And two classes that implement this interface public class...
Jon Skeet
people
quotationmark

Unless there's an == overload that you haven't shown, you're just comparing whether two references are equal - that's fine. You don't even need to cast wAction and tAction to object, as you can just use the implicit... more 8/4/2015 4:51:06 PM

people

Order of execution of fields and set/get in C#?

I am confused about the order of execution in C# regarding the setting of fields and set/get properties. Why is the value in Test2 not set when the constructor gets called while...
Jon Skeet
people
quotationmark

When an instance of a class is created is there some type of hidden/default "constructor" that sets the fields but does not call the setter of properties? Why would it call the property setters? What would it call them with? (Your... more 8/4/2015 3:42:43 PM

people

Will return keyword inside using statement, leave the connection open?

We are getting Timeout expired exception on SqlConnection.Open(). Below is the code : public int ExecuteNonQuery(SqlParameter[] param, string strSPName) { using...
Jon Skeet
people
quotationmark

Does the return keyword inside the using statement leaving the connection to opened and hence this issue? No. The using statement is effectively a try/finally block statement a Dispose call in the finally part - so your connection... more 8/4/2015 9:26:11 AM

people

With NodaTime, how do I format a ZonedDateTime in current culture

I have a ZonedDateTime and I want to display it such that the datetime is formatted with the short date and short time configured on the workstation followed by the offset...
Jon Skeet
people
quotationmark

g is fine as a standard pattern specifier - but only on its own; it can't be part of a custom pattern, which is what you're effectively trying to do here. You're effectively trying to mix and match, which we don't support :( As well as... more 8/4/2015 7:30:16 AM

people

Java KeyListener does not work, but ActionListener does

When click MenuItem NewGame. It works, but press F2 it doesn't mntmNewGame.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { ...
Jon Skeet
people
quotationmark

This is why you should always use @Override when overriding methods... KeyAdapter doesn't have a keyListener method - it has keyPressed, keyReleased and keyTyped. For example, you might want: mntmNewGame.addKeyListener(new KeyAdapter() { ... more 8/4/2015 6:07:11 AM

people

Java: Is "9" appearing in my run an Eclipse bug?

While writing my code for a computer dating assignment in which we see the compatibility of an array of four objects, my code printed strangely. (Eclipse didn't give me an...
Jon Skeet
people
quotationmark

No, it's not a bug. It's unusual, but it's not a bug. The first thing to do is simplify the example massively: public class Test { public static void main(String[] args) { String start = "Start"; String end = "End"; ... more 8/4/2015 5:20:13 AM

people

Creating an XML document with XElement using c#

I have an c# class, which inherits from another object, which contains lists of string. the structure is similiar to this: public class BeneficiaryScreening { public int Id {...
Jon Skeet
people
quotationmark

You just need to create a new XElement called value for each name: select new XElement("name", new XElement("value", name)) As an aside, I wouldn't use a query expression for that - I'd just use: new XElement("Entity", new... more 8/3/2015 4:43:16 PM

people