|
Was that an existential query?
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace multiplication
{
class Program
{
static void Main(string[] args)
{
int[,] a = new int[2, 2] { { 1, 2 }, { 3, 4 } };
int[,] b = new int[2, 2] { { 1, 2 }, { 3, 4 } };
int[,] c = new int[2, 2];
for (int i = 0; i <= a.Length; i++)
{
for (int j = 0; j <= b.Length; j++)
{
c[i, j] = (a[i, j] * b[i, j])+(a[i,,j+1]*b[i+1,,j]);
Console.Write(c[i, j]+ " " );
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
erorr is like
Index was outside the bounds of the array.
j somasekhar
modified 4-Jul-12 8:36am.
|
|
|
|
|
Please include the error-text, and the result that you were aiming for - ie, what should the code do?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
At first glance, there's a syntax error here (...) (a[i,,j+1]*b[i+1,,j]) (...) - note the consecutive commas, lose one of each.
Like this:
c[i, j] = (a[i, j] * b[i, j])+(a[i,j+1]*b[i+1,j]);
2A
|
|
|
|
|
For those who can't read minds, the exception you are getting is an out of bounds exception. The area that you are hitting this exception is here:
(a[i, j + 1] * b[i + 1, j]) The reason you are hitting this is because j+1 is 2 after the first iteration of j, which is outside of the bounds of the array. As I'm not sure what effect you are aiming at here, I can't really offer any concrete solution other than to say that you need to think through your logic here.
BTW - what length do you think is represented as a.Length or b.Length . It's not the 2 you're expecting; it's 4. Also, you are using <= in your conditions and it should be < only.
|
|
|
|
|
Nice catch! Have a five.
After spotting the syntax error in the code sample, I directly assumed that was the problem and stopped thinking right there...
2A
|
|
|
|
|
I spotted that error and figured it was just an error putting it into the CP editor. As soon as I saw that it was arrays and looping, I knew he'd have an out of bounds error in there somewhere. The rest was just figuring out where it was.
|
|
|
|
|
.
If that is meant to perform a matrix multiplication, then:
1.
it would require 3 nested loops, not 2, as each element (that is 2 loops) of the result matrix is to equal the inner product of one row and one column (that is the third loop, dealing with both the row of a and the column of b)
2.
I would not waste time on doing a specific case; instead use variable dimensions to make it general-purpose.
3.
And unless you want this as an exercise, there is a Matrix class that does it all for you, no hassle.
See e.g. here[^]
|
|
|
|
|
I have a stream object coming from mobile client in binary fromat as follows
name=tony&image=....raw binary representation of an image.....
I would like to extract the image out of the stream. I can extract the image and show it fine as long as string size preceding the binary image data is 16 chars or less! ("name=tony&image=") is 16 chars long
bool PostData(Stream stream)
{
using (FileStream filetoUpload = new FileStream(filePath + "ImageFromBytes.jpg", FileMode.Create))
{
byte[] byteArray = new byte[10000];
int bytesRead = 0;
bytesRead = stream.Read(byteArray, 0, byteArray.Length);
if (bytesRead > 0)
filetoUpload.Write(byteArray, 16, bytesRead-16);
....
}
}
If I do("name=randy&image=") = 17 chars long, it doesn't work, the image shows the right size, but can't be opened.
name=randy&image=....raw binary representation of an image.....
filetoUpload.Write(byteArray, 17, bytesRead-17);
Any ideas what in the world is going on?
|
|
|
|
|
I answered this question yesterday and explained that you need to parse the input stream. You cannot assume that every name will be only 4 characters long. You already have the marker characters that separate your objects (& ) and keyword value pairs (= ), so you should be scanning your input stream for those characters to split the data into its constituent parts.
|
|
|
|
|
Software2007 wrote: Any ideas what in the world is going on?
Sure - you have a randy image.
As you've discovered, you can't rely on fixed lengths in your string here - instead, you need to find the index of the second =. You can do this with string.IndexOf to find it. The good news is that you know where the first = is based on your key here, so all you need to do is use IndexOf starting on the value 5 (the position after name= in your string).
|
|
|
|
|
Pete O'Hanlon wrote: use IndexOf starting on the value 5 Not really a good suggestion based on the original question[^]. I get the impression he is trying to solve the problem by modifying the input data rather than getting to grips with the concept of parsing it.
|
|
|
|
|
Ah. I wasn't aware that he'd had an original question. Ho hum.
|
|
|
|
|
Another one that's probably going to run and run ...
|
|
|
|
|
|
Software2007 wrote: the image shows the right size
where? how?
Software2007 wrote: but can't be opened
when? by what program?
has your app exited already? did you wait a full minute and try again?
Please start taking the answers you get more seriously, and provide more detailed accurate information, so we all can help you more effectively.
|
|
|
|
|
Luc: The image doesn't open up on disk, meaning I can't view the image.
I have split the stream based on '&'. The bytes array apparently is full of them when it comes to image raw binary data. So, I decided to parse the string to the left of "image=". This is not where the problem is, the problem is after parsing, for the remaining image bytes, why can't I open the image correctly if the preceding string happens to be more than 16 chars long? The code above is only psuedo code, in reality this will be much longer string.
modified 4-Jul-12 13:24pm.
|
|
|
|
|
Is it the exact same binary data for both preceding lengths? If not, maybe the stream exceeds the size of your byteArray buffer? The byte array should be initialized at the length of the stream without your preceeding string, not sure if you are doing that in live code but from your example it is a static value. Giving more information on your stream length and maybe even a sample of how you are generating the image would be helpful?
|
|
|
|
|
If that's your best answer to my six questions, it stops here for me. Lacking the info, I'm not going to waste my time guessing what is going on.
|
|
|
|
|
This line was the problem, byte[] byteArray = new byte[10000];
I chose a randomly bigger number 20,000 and it works. But, it still doesn't make lot of sense to me. The bytesread for the image data alone is 5430. So, with extra 17 bytes string, I would think the 10000 would be still big enough?
Is there a way to know how much to allocate instead of just guessing a large number? Stream.length seems to be problematic for me. Remember, this is a network stream that I don't know the size of containing image data.
modified 4-Jul-12 17:25pm.
|
|
|
|
|
That is what I was talking about static values. If this is network stream you either need an end of message marker to make sure you read the whole message or read until nothing is left. You should be able to check what is available on the network stream and if multiple reads are required to get the entire message you may need to do some byte array manipulation (new byte() with current and new and use array.copy...) hope that is helpful.
|
|
|
|
|
Thanks. I will look into it.
|
|
|
|
|
I want to decompile a C# 2010 application. The only thing I have to work with is the deployment and setup project that I obtained from a contract shop. (I am pretty certain the code I obtained from the contract shop is not the most current version of the code.)
In addition, I would like to know what a good open source (free) tool and/or visual studio.net 2010 professional featuret I can use to compare the C#.2010 code. Basically I want to compare code that is in a visual studio.net professional environment to the same some that is obtained from a decompiler tool.
Basically I would like to know if the professional version of visual studio.net 2010 has these features? if so, what are they and how do I access these features.
If this is not avaialble, then what open source (free) tool(s) would you use? Of the tools you recommend, would you let me know if they are setup to work well with each other? Possibly there is one open source tool that would accomplish this goal?
|
|
|
|
|
|
I have not come across anything that is as good as the .net reflector.
Unfortunately, that is not free.
You can use the 30 day trial edition from here[^].
|
|
|
|