Browsing 7239 questions and answers with Jon Skeet

Get field descriptor in Protocol Buffers

Is there a way to get the field descriptor by using the given field number in protocol buffers? I know it exists for C++ (FindKnownExtensionsByNumber()) using reflection, however,...
Jon Skeet
people
quotationmark

I suspect you're looking for Descriptor.findFieldByNumber. Note that will find a field by number, not an extension. For extensions, use ExtensionRegistry.findExtensionByNumber. more 11/8/2013 10:42:08 PM

people

Set default value to member class in c#

I need to set a default value to a member class, this value can vary and it's set at the beginning of the execution; I have this so far, minScore is my default value public class...
Jon Skeet
people
quotationmark

Two options: Create a ZonesFactory class, which takes a defaultMinScore in the constructor (to remember) and has a CreateZones method which creates an instance and sets the min score: public class ZonesFactory { private readonly int... more 11/8/2013 9:16:58 PM

people

Return part of array

I am trying to find the fastest way to return a part of an array in C# My current way is as follows: // .. set int moveCount .. // .. set int[] childArray .. int[] realArray =...
Jon Skeet
people
quotationmark

No, when you return you'll be returning a reference to the array you've just created. The reference will be copied, but that's dirt cheap. All arrays are reference types, even if the element type of the array is a value type (so int[] is... more 11/8/2013 8:34:07 PM

people

How to check for negative values in text box in VB?

How to we check for negative values in a text box? I was only able to TryParse the text box so that there it will validate it if it's a numeric value: If Not...
Jon Skeet
people
quotationmark

Your If condition is basically saying if it hasn't successfully parsed it as a number. You want something like: If Decimal.TryParse(txtParts.Text, decParts) Then If decParts <= 0 Then MessageBox.Show("ERROR: Value must be a... more 11/8/2013 8:31:15 PM

people

Can not make method with same parameter types

I am having 2 Entity to Dto map methods with the same parameter which is not allowed for the same name. Is the only problem to solve give ToDto a better name? Actually I like...
Jon Skeet
people
quotationmark

How would you expect the compiler to work out which one you meant? Yes, if you're trying to create different methods with the same parameters, you need to give them different names. I would suggest ToBrowseDto and ToEditDto. Then it's... more 11/8/2013 8:18:22 PM

people

Why can't I catch an exception from async code?

Everywhere I read it says the following code should work, but it doesn't. public async Task DoSomething(int x) { try { // Asynchronous implementation. await...
Jon Skeet
people
quotationmark

Your code won't even compile cleanly at the moment, as the x++; statement is unreachable. Always pay attention to warnings. However, after fixing that, it works fine: using System; using System.Threading.Tasks; class Test { static... more 11/8/2013 6:02:22 PM

people

Error sqlcommand.ExecuteNonQuery()

I have a table in my sql server 2008 database COMMENT(idcom,content,username); This table has 2 records which username = lecturer Now I want to delete all comments which have...
Jon Skeet
people
quotationmark

I suspect the value of userdeleted is just lecturer rather than 'lecturer'. Therefore your SQL statement is: DELETE FROM COMMENT WHERE USERNAME=lecturer That's the immediate problem - it's looking for a column called lecturer. If you... more 11/8/2013 5:40:16 PM

people

Why aren't these two arrays equal?

public static void main(String[] args) { char [] d = {'a','b','c','d'}; char [] e = {'d','c','b','a'}; Arrays.sort(d); Arrays.sort(e); System.out.println(e); ...
Jon Skeet
people
quotationmark

Isn't the result supposed to be true? No. You're calling equals on two different array references. Arrays don't override equals, therefore you get reference equality. The references aren't equal, therefore it returns false... To... more 11/8/2013 5:36:09 PM

people

Im getting error on visual studio 2010: The type or namespace name 'HttpUtility' does not exist

How can i solve it ? If im doing in my code: using System.Web; it dosent help I tried ot add reference of System.Web.ApplicationServices didnt help also tried to reference:...
Jon Skeet
people
quotationmark

The project is set on Target Framework to: .net 4 client profile. That's the problem. HttpUtility doesn't exist in the client profile. Target the full profile instead (and make sure you have a reference to System.Web.dll). Compare... more 11/8/2013 4:53:08 PM

people

Issue with inDaylightTime() and determing if a date is in daylight savings time

Have been beating my head against this and not sure what I'm doing wrong here. I am testing out the inDaylightTime() method for a certain time zone but it is returning "false"...
Jon Skeet
people
quotationmark

You're specifying a time zone of GMT-8:00 - that's a fixed time zone, which is 8 hours behind of UTC permanently. It doesn't observe daylight saving time. If you actually meant Pacific Time, you should specify America/Los_Angeles as the... more 11/8/2013 4:36:32 PM

people