Browsing 7239 questions and answers with Jon Skeet

How to test if an input value = char A Z in C#

while (asteriskWord != hangCharacters && score < 5) { while ( letter != ) //This is where I want to test for A-Z a-z { ...
Jon Skeet
people
quotationmark

Well the simplest way would be to just use comparisons. If you definitely want to do it in a single expression, Glorfindel's answer is appropriate. However, all those brackets and the negation makes me nervous of the readability. I'd break... more 6/4/2015 8:37:09 PM

people

Cost of reflection: WPF

I have implemented an extension helper to load a WPF usercontrol to a window dynamically. (MyButton is in another assembly). This helper is in a class lib that is used in all my...
Jon Skeet
people
quotationmark

If you know the type at compile-time, you'd be a lot better off making this generic: // Possibly add more generic constraints to T? public static Window OpenUserControl<T>(string title) where T : new() { return new Window ... more 6/4/2015 7:26:20 PM

people

Scope of global variables in a java class and their behavior in methods of the same class

I am new to programming and Java and I have some confusion regarding the behavior of global variables in methods of the same class. In an exercise question provided by the course...
Jon Skeet
people
quotationmark

In other words, why is the variable change "forgotten" in the above example, but "remembered" in a set method? In your inc method, you're not changing the field called b at all. You've got a parameter called b, so every time the code... more 6/4/2015 7:12:44 PM

people

How to access value out of dictionary whose key is complex type?

In writing an insurance premium calculator the basic scheme is as follows: Points are assigned to a predetermined number of attributes, such as car-value, num-incidents-in-past,...
Jon Skeet
people
quotationmark

(As noted in comments, Sam's answer points out that a dictionary isn't really what's wanted here - that only finds equal keys, whereas the OP is trying to find a range key that contains a single value. Hash tables just aren't geared up for... more 6/4/2015 3:13:01 PM

people

JSONArray Parsing error

I need help with parsing a JSON array. [ { "Header1": [ { "path": "upload/images/1430572021716.jpg" }, { ...
Jon Skeet
people
quotationmark

You're trying to treat each element of the top-level array as another array - it's not, it's an object. That object then has another field whose value is an array. So you want something like: for (int i = 0; i < json.length(); i++) { ... more 6/4/2015 2:38:30 PM

people

Why static variable is shared among the threads

In almost all the posts I have read - If two Threads(suppose Thread 1 and Thread 2) are accessing the same object and updating a variable which is declared as static then it...
Jon Skeet
people
quotationmark

I think you're being confused by the dangers of the memory model. Static variables are shared between threads - the articles you've been reading haven't been trying to say that each thread has its own independent set of static variables.... more 6/4/2015 1:03:35 PM

people

jpeg to byte array, while conversion logic is inside if statement

I'm sure this is a very simple issue that even inexperienced developers would be able to do, but I'm just starting out. I've put an if statement round the logic to convert a jpeg...
Jon Skeet
people
quotationmark

Well, you need to declare the logoBytes variable outside the if statement so that it's still in scope when you create the TemplateData. You need to decide what value it should have if there isn't a file provided. For example, you might... more 6/4/2015 12:24:12 PM

people

Java random shuffle list with two elements using Collections.shuffle

import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Random; public class ShuffleList { public static void main(String[] args) { ...
Jon Skeet
people
quotationmark

The problem isn't with shuffle - it's with Random with small seeds. Here's a program demonstrating that: import java.util.Random; public class Test { public static void main(String[] args) { int total = 0; for (int... more 6/4/2015 8:15:33 AM

people

How to check the containers running on a pod in kubernettes?

I am able to get a list of all pods running on a kubernetes cluster using: kubectl get pods How do I get all the containers running on a particular pod?
Jon Skeet
people
quotationmark

You can use the describe command: kubectl describe pod [podname] That will specify which containers are in the pod, along with other information. more 6/4/2015 7:19:36 AM

people

bundled executable jar file couldnot find main class

I am trying to execute a jar file StartupUtil.jar but it's giving an error of Couldnot find and load main class. I looked at other similar question and tried but couldnot figure...
Jon Skeet
people
quotationmark

I strongly suspect that the problem is it can't find the dependencies, which means it can't properly load the main class. I've never seen absolute filenames given in a manifest before, nor am I convinced about how you're breaking the lines... more 6/4/2015 5:58:00 AM

people