Click here to Skip to main content
15,910,877 members
Home / Discussions / C#
   

C#

 
GeneralRe: send variable across webpages without using session Pin
Rahul VB21-Jan-14 8:33
professionalRahul VB21-Jan-14 8:33 
GeneralRe: send variable across webpages without using session Pin
OriginalGriff21-Jan-14 8:46
mveOriginalGriff21-Jan-14 8:46 
GeneralRe: send variable across webpages without using session Pin
Sharath Surendran21-Jan-14 22:50
Sharath Surendran21-Jan-14 22:50 
AnswerRe: send variable across webpages without using session Pin
Shameel21-Jan-14 23:10
professionalShameel21-Jan-14 23:10 
GeneralRe: send variable across webpages without using session Pin
Sharath Surendran21-Jan-14 23:15
Sharath Surendran21-Jan-14 23:15 
AnswerRe: send variable across webpages without using session Pin
thatraja21-Jan-14 0:22
professionalthatraja21-Jan-14 0:22 
GeneralRe: send variable across webpages without using session Pin
Sharath Surendran21-Jan-14 22:54
Sharath Surendran21-Jan-14 22:54 
QuestionNeed help for perform some operation parallely Pin
superselector20-Jan-14 17:31
superselector20-Jan-14 17:31 
AnswerRe: Need help for perform some operation parallely Pin
Ron Beyer20-Jan-14 17:38
professionalRon Beyer20-Jan-14 17:38 
GeneralRe: Need help for perform some operation parallely Pin
superselector20-Jan-14 20:39
superselector20-Jan-14 20:39 
GeneralRe: Need help for perform some operation parallely Pin
OriginalGriff20-Jan-14 22:52
mveOriginalGriff20-Jan-14 22:52 
AnswerRe: Need help for perform some operation parallely Pin
GuyThiebaut20-Jan-14 21:55
professionalGuyThiebaut20-Jan-14 21:55 
GeneralRe: Need help for perform some operation parallely Pin
Ron Beyer21-Jan-14 2:26
professionalRon Beyer21-Jan-14 2:26 
GeneralRe: Need help for perform some operation parallely Pin
GuyThiebaut21-Jan-14 5:41
professionalGuyThiebaut21-Jan-14 5:41 
GeneralRe: Need help for perform some operation parallely Pin
GuyThiebaut21-Jan-14 6:27
professionalGuyThiebaut21-Jan-14 6:27 
GeneralRe: Need help for perform some operation parallely Pin
Ron Beyer21-Jan-14 7:01
professionalRon Beyer21-Jan-14 7:01 
QuestionHelp writing a program which adds up values in a 2D array to determine if it is a magic square Pin
Member 1052812320-Jan-14 3:43
Member 1052812320-Jan-14 3:43 
AnswerRe: Help writing a program which adds up values in a 2D array to determine if it is a magic square Pin
Peter Leow20-Jan-14 4:20
professionalPeter Leow20-Jan-14 4:20 
AnswerRe: Help writing a program which adds up values in a 2D array to determine if it is a magic square Pin
OriginalGriff20-Jan-14 5:50
mveOriginalGriff20-Jan-14 5:50 
AnswerRe: Help writing a program which adds up values in a 2D array to determine if it is a magic square Pin
BillWoodruff20-Jan-14 9:08
professionalBillWoodruff20-Jan-14 9:08 
You do realize that if you generate a #Nx#N matrix of random numbers the chance the result will satisfy the conditions for being a magic square are very low ... and, that as the size of the matrix increases, the chances get exponentially less and less ?

For validating whether your #Nx#N matrix is a magic square: traversing it using for-loops is quite straightforward, if tedious, but it's a good exercise to improve your mastery of for-loops to implement, I think. If you are new to C#, you might benefit from actually writing out the series of for-loop indexes you require for each test case (rows, columns, right-left diagonal, left-right diagonal).

If you are studying Linq and switch to using something like a List<List<int>> to hold your matrix, then Linq's operators like 'Sum can make validation much easier.
C#
// requires System.Linq
// requires System.Collections.Generic

// test the rows of the Magic Square
private bool testMagic(List<List<int>> testSquare)
 {
     // get first [0] row sum
     int firstRowSum = testSquare[0].Sum();

     // check rows #1 to #n
     for (int i = 1; i < magicNSides; i++)
     {
         // stop immediately on mis-match
         if (testSquare[i].Sum() != firstRowSum) return false;
     }

     return true;
}
For testing the Rows using Linq it can be even simpler:
bool IsMagicRows = squareList.All(x => (x.Sum() == firstRowSum));
Whichever strategy you use, validation in this case, imho, is best done in a way where you do a series of tests, and stop testing the moment any one of them fails.

For example, if you calculate the sum of the items on the first row of your array (or in the first List<string> inside your List<List<int>>) then you can start testing the other rows and stop immediately if any row does not have a sum equal to the sum of the first row.
“But I don't want to go among mad people,” Alice remarked.

“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”

“How do you know I'm mad?” said Alice.

“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll


modified 20-Jan-14 15:24pm.

QuestionCustom Data Types Pin
sunsilk1020-Jan-14 3:04
sunsilk1020-Jan-14 3:04 
AnswerRe: Custom Data Types Pin
Manfred Rudolf Bihy20-Jan-14 3:25
professionalManfred Rudolf Bihy20-Jan-14 3:25 
AnswerRe: Custom Data Types Pin
BillWoodruff20-Jan-14 5:13
professionalBillWoodruff20-Jan-14 5:13 
AnswerRe: Custom Data Types Pin
Freak3020-Jan-14 23:30
Freak3020-Jan-14 23:30 
QuestionC# with Oraclei Pin
Nightbird.14319-Jan-14 21:00
Nightbird.14319-Jan-14 21:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.