Browsing 7239 questions and answers with Jon Skeet

How to get a Roslyn FieldSymbol from a FieldDeclarationSyntax node?

I'm trying to use Roslyn to determine the publically-exposed API of a project (and then do some further processing using this information, so I can't just use reflection). I'm...
Jon Skeet
people
quotationmark

I've been here several times :) You need to remember that a field declaration syntax can declare multiple fields. So you want: foreach (var variable in node.Declaration.Variables) { var fieldSymbol =... more 1/8/2015 8:07:13 PM

people

NUnit Gets Different Hash Code Values from ReSharper vs Visual Studio 2013

I have a fairly simple GetHashCode() implementation in C# as per Jon Skeet's answer here. Here is my code: public override int GetHashCode() { unchecked { int...
Jon Skeet
people
quotationmark

You're probably using the 32-bit CLR in one test runner and the 64-bit CLR in another. The implementation of string.GetHashCode differs between the two. You should not depend on them being consistent between runs - they only have to be... more 1/8/2015 7:36:39 PM

people

Convert String To Enum in a portable lib

I'm trying to convert a string to an Enum, in a generic way, in a portable class Library Targes are: .NET 4.5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8 I have...
Jon Skeet
people
quotationmark

If Type.IsEnum isn't supported, you could always use: if (typeof(TEnum).BaseType != typeof(Enum)) (Assuming BaseType is available, of course.) more 1/8/2015 12:43:27 PM

people

Trouble looping through array

I'm trying to loop through the array, and if all the elements are equal or less than zero it will display the winner screen. At the moment, it displays the winner screen when the...
Jon Skeet
people
quotationmark

There are a few issues here: You're calling parent.mygame.getplayer(parent.mygame.getpturn()).getmonsterarray() on every iteration of the loop, which is at least a bit inefficient, and also makes the code harder to read. You should... more 1/8/2015 11:48:34 AM

people

Empty string gets passed from one Form to another in Winforms

I have following problem: I have a Form1 where I open a second Form2 from it. Now I have a save Button in Form2 where entries from Textboxes are saved to a csv file. But I want to...
Jon Skeet
people
quotationmark

In the click handler, you're creating a new Form1 here: Form1 form1 = new Form1(); That will have empty values - but you want the value from the existing form which you kept a reference to in your constructor - so use it! private void... more 1/8/2015 10:56:19 AM

people

Random and graphics too long code

I want to create a random number, then create 9 rectangles but one of them will be in a different color, the one with the different color will be according to the random number...
Jon Skeet
people
quotationmark

I would start off by writing a helper method: private static void drawRectangle(Graphics g, int column, int row, Color color) { // TODO: Remember the previous color of g and reset it afterwards? g.setColor(color); ... more 1/8/2015 10:51:43 AM

people

How to handle nameof(this) to report class name

I'd like to use the following C#6 code var joe = new Self(); Console.WriteLine(joe); ... and get the following output: joe The following attempt class Self { public...
Jon Skeet
people
quotationmark

No, nameof is designed to refer to the compile-time name of the member you're referring to. If you want an object to have a Name property as part of its state, that is independent of how you get to the Name property - as Frédéric Hamidi... more 1/8/2015 10:33:57 AM

people

Java Application crashed on Thread.sleep method

I have a function for my monsters to walk. It will be able to choose the direction and distance randomly and move the monster when called. Right now I have the method being called...
Jon Skeet
people
quotationmark

I haven't used LWJGL myself, but in almost every UI framework I've seen, there's one thread which is reserved for UI operations: You mustn't perform UI operations on any other thread You mustn't tie that thread up for any significant... more 1/8/2015 10:14:15 AM

people

Using out parameter in the console app c#

I am using a console app using C# that has a method that calls another method and passes an out parameter public void method1() { int trycount = 0; ...
Jon Skeet
people
quotationmark

It sounds like you want a ref parameter instead of an out parameter. Basically out is like having an extra return value - it doesn't logically have a value initially (it's not definitely assigned, and has to be definitely assigned before... more 1/7/2015 9:18:44 PM

people

Why can the type arguments not be inferred, and how can I specify them explicitly?

This code, adapted from an answer here works in a .NET 4.5.1 app in Visual Studio 2013: private void button42_Click(object sender, EventArgs e) { List<SiteQuery>...
Jon Skeet
people
quotationmark

Type inference changed in VS2010 (IIRC) - basically the compiler became slightly more capable. It's not a matter of .NET itself changing. Two simple options: Use a lambda expression instead: .Select(x =>... more 1/7/2015 9:11:20 PM

people