[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

c#

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 17
Thread images: 1

File: 1482080441611.jpg (164KB, 360x543px) Image search: [Google]
1482080441611.jpg
164KB, 360x543px
Can someone explain what form data has to take to work on this simple swapping function?


public static void exchange (int[] data, int m, int n)
{
int temporary;

temporary = data [m];
data [m] = data [n];
data [n] = temporary;
}

from link:
http://anh.cs.luc.edu/170/notes/CSharpHtml/sorting.html
>>
>>351963
An array of ints at least as long as m and at least as long as n, no?
>>
>>351984
How?

I've tried it like this:
int m = 2;
int n = 10;
int[] data = new int[] { 3, 5, 4, 6 };

But this comes out:
"
Error CS7036: There is no argument given that corresponds to the required formal parameter 'data' of 'Program.DoStuff(int[], int, int)'
"
>>
>>352202
Bump. Still need help with this.
>>
>>352507
Bump, please help.
>>
It takes an array of integers as its first argument and two integers. however, both integers must be in the range of 0 to n where n is the number of entrys in the array minus 1. YOu got the error because your array only has 4 entries and you tried to access the tenth one with your m.
>>
so to make it work with m=2 and n=10 your array has to at least have eleven entries (because arrays start at 0)
>>
>>352694
>>352696
Okay thanks, so I've changed it up to:
int[] data = new int[] {3, 4, 6, 5, 7, 3, 5, 2, 8, 5, 7};

But still get the error message. What have I done wrong?
>>
>>352696
Compiler isn't that smart.

>>352699
Do you have some kind of pathological aversion to posting your whole fucking code?

It's going to be all of ten lines, but you keep cherry picking the lines where the error isn't.
>>
what does your exchange/DoStuff function call look like?
>>
>>352845
>>352882
using System;
using System.IO;
using System.Linq;
class Program
{

static void Main(string[] args)
{
int m = 2;
int n = 10;
int[] data = { 3, 5, 4, 6, 8, 7, 9, 4, 5 };

DoStuff();

//Exhange();

Console.ReadLine();
}

public static void DoStuff(int[] data, int m, int n)
{
int temporary;

temporary = data [m];
data [m] = data [n];
data [n] = temporary;
}

}


Here.
>>
>>352920
You're not calling DoStuff(...) with any parameters.

C doesn't look at your variable names, notice they're the same as the ones in the function definition, and just put them in for you: you have to tell it.

DoStuff(data,m,n);

If you've have just done like >>352845, in the first place, this thread could have been done and dusted in seconds rather than days.
>>
>>352923
This is what happens when kids try to walk before they can crawl. The fucker is looking at sorting algorithms and doesn't even know how code actually works.
>>
>>352923
Okay duly noted. Thanks. So I've done that.

>>352924
Let's just say I've left something a little too late and haven't sought help before this point. I am a fool.
>>
>>352920
>DoStuff();
thats what i tought
>>
>>352920
Also data doesn't have enough items in it for n to equal 10. You have 9 items in there, it needs 1 more, and you need to subtract 1 from 10 because arrays count from 0, not from 1.
>>
>>353108
That's not an issue that affects compilation: in C# the compiler does not check array bounds, and is in any case not smart enough to perform that kind of static analysis.

C# does do runtime bounds-checking, though, so OP would be told that by the .NET runtime the first time he pressed "run".
Thread posts: 17
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.