Browsing 7239 questions and answers with Jon Skeet

Eclipse: How can I add a library?

it sounds probably really dumb, but how can I add a library to Eclipse? I'm trying this one, but I have no idea how to do it: http://code.google.com/p/streamscraper/ I tried...
Jon Skeet
people
quotationmark

One simple way, assuming it's a jar file: Make sure the jar file is in your project directory (so it should show up in package explorer) Right-click the project root Choose "Build path" / "Configure build path..." Go to the "Libraries"... more 9/21/2013 3:29:40 PM

people

Need help getting system to read fields from Form2 C#

I am creating a small program that speaks and can do minor tasks for me. I want to create a second form (Form2) in which I will type in my name and other personal info. How can I...
Jon Skeet
people
quotationmark

How can I get Form1 to read the textfields in Form2? Presumably Form1 creates an instance of Form2... so hold on to that instance, and expose appropriate properties on the form: Form2 form2 = new Form2(); form2.Show(); // Or... more 9/21/2013 3:19:06 PM

people

call a method from another method in Code behind C#

I need to call btn_submit_Click(object sender, EventArgs e) from another method protected void Timer1_Tick(object sender, EventArgs e) which normally calls by a button click. Now...
Jon Skeet
people
quotationmark

Personally I would take a slightly different approach. You're not actually trying to say that a button was clicked - you're just interested in the same side effects as a button click. So extract a third method which only has the relevant... more 9/21/2013 8:07:30 AM

people

The program behavoir is different on different systems. why ?

This is the code of my program: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace YourGold { class Program { ...
Jon Skeet
people
quotationmark

I strongly suspect that when you run it locally, you're in a culture where , is the decimal separator rather than . - and perhaps . is the thousands separator, which is basically ignored. So 1.5 ends up being parsed as 15 hours, which is... more 9/21/2013 7:22:48 AM

people

How to Compare two time values (from Datetime) without Date in C#

I have put a timer on my ASPX page, Where on tick it updates the "currenttime" on a asp:label called Label1, however when the page loads I store a DateTime value called "endtime",...
Jon Skeet
people
quotationmark

Just use the TimeOfDay property: if (currentTime.TimeOfDay == endTime.TimeOfDay) ... although I suspect you want to use >= instead of ==. If you do, be careful of the situation where endTime is just before midnight... if currentTime... more 9/21/2013 7:18:17 AM

people

conditional operator usage in the below code

I was using the conditional operator as shown below.. String AccessType = (a.isActive() && b.isActive() ? "Active" : "NotActive"); Now I want that if a.active is true...
Jon Skeet
people
quotationmark

Your implementation is already correct. The "laziness" aspect (only calling b.isActive() if a.isActive() returns true) is taken care of by the behaviour of the && operator, which is short-circuiting. From section 15.23 of the... more 9/21/2013 6:05:57 AM

people

I am getting the memory address from an arraylist, need info

I am taking a text file and filling an arraylist. To test the file I am printing it out before I move on. I am only able to see the memory address and not the actual info from the...
Jon Skeet
people
quotationmark

Is there something simple and probably obvious I'm missing? Yes - you haven't overridden toString in TriviaQuestion, so you're getting the default implementation from Object: The toString method for class Object returns a string... more 9/21/2013 5:13:01 AM

people

Java Multithreading make threads end in same order they started but run at same time

I have to make a program that searches through a bunch of lines from a file and tries to find a given substring. If it finds it, it prints out the line. Each line that I read is...
Jon Skeet
people
quotationmark

I can not use the join method as I don't want the next one to wait for the other to finish entirely before starting, I do want them to be running at the same time. You could make them populate an array (where each one "knows" the... more 9/20/2013 9:37:47 PM

people

How does List<Struct>.Contains() work?

I have programed a very simple struct in C# (I'm using Visual Studio 2012 with .NET 4.5) public struct MyStruct { public Int32 X { get; set; } public Int32 Y { get; set;...
Jon Skeet
people
quotationmark

How does the .Contains() method perform the comparison? It uses the default equality comparer for the type, as documented: This method determines equality by using the default equality comparer So essentially, something like... more 9/20/2013 9:32:54 PM

people

Currency output unsing number format class in java

I'm not sure how to use the number format class in order to have a double format into US currency,. For example if tuition is 1000 ,I would need it to print out $1,000.00 .I will...
Jon Skeet
people
quotationmark

You need to use NumberFormat.getCurrencyInstance(...), and then use that to format your value. For example: public String toString() { NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.US); return "\nOnline... more 9/20/2013 9:07:32 PM

people