Browsing 7239 questions and answers with Jon Skeet

Why is my display() method not printing out all ArrayList elements?

I have a class Container where a user should be able to input any number of words until he types nothing. I have addWord(Word) method where each input is added to an ArrayList...
Jon Skeet
people
quotationmark

Look at your addWord method: public void addWord(String word) { words = new ArrayList<String>(); words.add(word); ... more 12/3/2017 8:18:21 PM

people

Check if a string consists only of letters and / or hyphens with matches?

Good evening from Cologne. In a programming task I have to check if the given string consists only of letters and / or hyphens. Now I have an approach with matches. In the test...
Jon Skeet
people
quotationmark

Currently you're checking whether it's all letters, or all hyphens. You just need to check whether it matches letters or hyphens: public static boolean istName(String a) { return a.matches("[a-zA-Z-]+"); } The - at the end means "a... more 12/3/2017 6:38:55 PM

people

PadRight in string of arrays doesn't add chars

I created array of strings which includes strings with Length from 4 to 6. I am trying to PadRight 0's to get length for every element in array to 6. string[] array1 = { ...
Jon Skeet
people
quotationmark

The first argument to PadRight is the total length you want. You've specified 6 - array1[i].Length - and as all your strings start off with at least 3 characters, you're padding to at most 3 characters, so it's not doing anything. You... more 12/3/2017 6:08:31 PM

people

C# json parse string inside 2nd curly brackets {X{Y}}

I try to parse string inside 2nd curly brackets using C# / json String looks like this: {"R27":{"DEVX":0.1346224}} My aim is read value of DEVX, which is 0.1346224 I've...
Jon Skeet
people
quotationmark

Yes, absolutely - assuming you know the two names involved, you can just index twice, once to get the object for R27, then once within that object to get the value of DEVX: using System; using Newtonsoft.Json.Linq; public class Test { ... more 12/3/2017 8:47:46 AM

people

throw null in decompiled ArraySegment

I've just had a look at the ArraySegment class in .NET Core (...\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.Runtime.dll). Every method\property just has throw null in...
Jon Skeet
people
quotationmark

You're looking at the reference assemblies. That's not the real implementation - it's just a placeholder to compile against, effectively. You'll see the assembly only has the public/protected members, and every code-based member... more 12/1/2017 11:42:45 AM

people

Google Cloud Speech streaming in the Unity Game Engine

I would like to know if anyone has been succesful with implementing Google Cloud Speech (streaming) into the Unity Game Engine? It would be wonderful if Google's Speech technology...
Jon Skeet
people
quotationmark

No, streaming in Google Cloud Speech API requires gRPC, and gRPC isn't supported in Unity at the moment. Once gRPC is supported, I'd expect the client library to port very easily - or just work out of the box, potentially. Supporting gRPC... more 12/1/2017 10:35:21 AM

people

Disagreement about string is a primitive type

As you know, MSDN library says that string, decimal and object are not primitive types. I'm sharing a quote about this: The primitive types are Boolean, Byte, SByte, Int16,...
Jon Skeet
people
quotationmark

I wouldn't personally call dynamic, decimal, object or string primitive types. I'd use Type.IsPrimitive for the canonical source there. Note that dynamic isn't even a type in the CLR sense. The C# 5 MS specification only uses the word... more 12/1/2017 8:57:24 AM

people

Error message "CS5001 Program does not contain a static 'Main' method suitable for an entry point"

Unable to execute the following code error CS5001 Program does not contain a static 'Main' method suitable for an entry point What does this error message mean? class...
Jon Skeet
people
quotationmark

It means that you don't have a suitable entry point for your application at the moment. That code will nearly work with C# 7.1, but you do need to explicitly enable C# 7.1 in your project... more 12/1/2017 7:28:54 AM

people

LINQ is converting string to special characters

I am using this query to get data from database. string nfc = "53f8372c"; var temp = db.tempTable.AsNoTracking().Where( x => ...
Jon Skeet
people
quotationmark

That's just parameterizing the SQL. If you look at the parameters passed to the query, you'll see that :p__linq__0 has a value of 53f8372c. This parameterization is helpful, as the server can cache the query plan and reuse it for the same... more 11/30/2017 6:15:27 PM

people

Let current thread finish using the function before letting other threads call it C#

I can't seem to get thread.Join() to work for this example. I'm new to multithreading and C# so I am kind of unsure how to apply the online examples into my own coding. Here's an...
Jon Skeet
people
quotationmark

It sounds like you just want a lock, using a static field for an object whose monitor you lock on: private static readonly object lockForSharedMethod = new object(); ... private static void SharedMethod() { lock(lockForSharedMethod) ... more 11/30/2017 7:10:11 AM

people