Browsing 7239 questions and answers with Jon Skeet

C# How I can expect a exception in Assert.AreEqual?

Example: Assert.AreEqual(**null**, Program.nDaysMonth(5, -10), "Error nDaysMonth, Month may -10."); I expect a exception. How I can expect a exception in...
Jon Skeet
people
quotationmark

You don't use Assert.AreEqual, you use Assert.Throws: Assert.Throws<ArgumentOutOfRangeException>(() => Program.nDaysMonth(5, -10)); This checks that the correct exception is thrown. If you want to add more assertions, you can... more 5/19/2015 1:48:33 PM

people

How should I assign the fractional part to a BigDecimal that comes from a tFileInputPositional in Talend?

I'm working with Talend Open Studio for Data Integration. I've got a tFileInputPositional which creates several fields. One of them would look like this: "+0000030139808303". I...
Jon Skeet
people
quotationmark

I suspect you just want BigDecimal.movePointLeft. Returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left. If n is non-negative, the call merely adds n to the scale. If n is negative, the... more 5/19/2015 9:10:25 AM

people

Does adding optional parameters change method signatures and would it trigger method missing exception?

We have several projects that are referencing library assembly lets call "myUtil", now one of the method which is referenced in several projects is, GetData(int p1, string p2,...
Jon Skeet
people
quotationmark

You don't need to remove and re-add the reference, but you do need to rebuild all of the projects that compile against the DLL. Adding an optional parameter is a source-compatible but not a binary-compatible change, because the compiler... more 5/19/2015 5:50:09 AM

people

Get value from xml element in c#

I am trying to get Absoluteentry tag's value from the below xml string, but its displaying objectrefrence not set exception <?xml version="1.0" ?> <env:Envelope...
Jon Skeet
people
quotationmark

Look at the XML: <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> ... That's the Envelope element in the namespace with URI "http://www.w3.org/2003/05/soap-envelope". Now look at your... more 5/18/2015 7:07:10 PM

people

TCP server not receiving all data being sent

Attempting to setup a TCP server to grab data from a stream. Seems to be working, but only when the stream is small. Once I start sending large amounts of data, this fails, only...
Jon Skeet
people
quotationmark

You seem to be expecting to receive an entire XML document - and exactly the XML document - each time you call Stream.Read. That's a really, really dangerous assumption. The stream is a stream of data - while it'll be segmented into... more 5/18/2015 6:42:28 PM

people

How to get List<obj> from async Task<List<obj>>

I have this code to fetch an RSS feed async via HttpClient. How do I call this from an MVC controller and pass the data back to the view as a List<RssFeedItem>? public...
Jon Skeet
people
quotationmark

How do I call this from an MVC controller and pass the data back to the view as a List<RssFeedItem>? Usually, you'd do this in another async method, and await the result. For example: public async Task<ActionResult>... more 5/18/2015 5:55:19 PM

people

What is the most significant byte of 160 bit hash for arithmetic operations?

Could somebody help me to understand what is the most significant byte of a 160 bit (SHA-1) hash? I have a C# code which calls the cryptography library to calculate a hash code...
Jon Skeet
people
quotationmark

You should think of the initial hash as just bytes, not a number. If you're trying to order them for indexed lookup, use whatever ordering is simplest to implement - there's no general purpose "right" or "conventional" here, really. If... more 5/18/2015 5:45:52 PM

people

Conversion of double to int

I want to input the W into the int array. How can i do that? Sorry for the lousy question or english. public void setX (int Y , double W) { array[Y] = W; }
Jon Skeet
people
quotationmark

If you're happy to truncate towards 0 - and get int.MIN_VALUE or int.MAX_VALUE if the value is out of the range of int - you can just cast: array[Y] = (int) W; If you're not happy with those caveats, you should re-evaluate your design -... more 5/18/2015 4:39:03 PM

people

" ; expected " error while setting array value

string[] aryProp = { "Name", button.Name }; //ListViewItem lvi = new ListViewItem(aryProp); aryProp={ "Width" , button.Width.ToString() }; " ; expected " (line 3) Why am I...
Jon Skeet
people
quotationmark

Why am I getting this error ? Because while your syntax is valid for initialization in a variable declaration, it's not valid for a plain assignment. You can use: aryProp = new[] { "Width" , button.Width.ToString() }; Or: aryProp... more 5/18/2015 2:11:36 PM

people

Image to ByteArray to BLOB and BLOB to ByteArray to Image Conversion Issues in Java

After a lot of learning on ByteArrays & BLOBS, I managed to write the below Java code to write an image into Access DB (Using ucanaccess) and writing it back to Disk. When I...
Jon Skeet
people
quotationmark

Firstly, you should separate this into two parts: Storing binary data in a database and retrieving it Loading an image file and saving it again There's no need to use a database to test the second part - you should diagnose the issues... more 5/18/2015 11:01:39 AM

people