|
I want to define a class (which will store a 2D matrix and will do some operations on that).
Say I want to define a 2D matirx [1 2 3 ;1 2 3; 3 4 5] and I have a GUI to enter the data, where I enter <big>matrix(1,2,3;1,2,3;3,4,5)</big> and it constructs the matrix [1 2 3 ;1 2 3; 3 4 5].
Can someone help me how to acheive this?
|
|
|
|
|
Maybe you can do something like
new Matrix(
new MatrixRow(1, 2, 3),
new MatrixRow(1, 2, 3),
new MatrixRow(3, 4, 5)
);
Does that help?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
To store a two dimensional array, you use an array of arrays.
int[][] matrix;<br />
matrix = new int[3][];<br />
for (int i=0; i<3; i++) matrix[i] = new int[3];
Now you have a 3x3 array that you can store the values in.
---
b { font-weight: normal; }
|
|
|
|
|
But only problem is that i don't know what will be the size of the mastirx before hand. I just gave u an example ,..it could be any n*m matrix.
|
|
|
|
|
You can replace the numbers with variables containing any number you want.
---
b { font-weight: normal; }
|
|
|
|
|
Have you worked in MATLAB? its like nothing is mentioned? you just enter
>>[1 2 3,4 5 6;8 9 6]
and it creates a matrix. i want some application lik ethat. by looking at the expression user entered you construct the matrix. i know we can do that by defiing a variable. but how to determine th eorder of the matrix (n*m) by looking at the expression. bec as far as i know constructor takes only parameters. trick here is that by looking at the string 1 2 3,4 5 6;8 9 6 your constructor should be able to say that it is a 3*3 matrix and defines the matrix accordingly
|
|
|
|
|
Split the string by semicolon:
string input = "1 2 3;4 5 6;7 8 9";<br />
string[] rows = input.Split(';');
Now you have an array with three records. Create an array of string arrays to store the final result:
string[][] matrix = new string[rows.Length][];
Now split each row by space to get an array, and put it in the matrix:
for (int i=0; i<rows.Length; i++) matrix[i] = rows[i].Split(' ');
---
b { font-weight: normal; }
|
|
|
|
|
Thanks..solves my problem. u exactly got into the root of the problem.
|
|
|
|
|
Note though that the code does not check if the matrix is square. It will happily turn a string like "1;2 3 4 5;;6;7;8 9" into arrays without complaining.
---
b { font-weight: normal; }
|
|
|
|
|
Hi all,
I've started coding a windows form without the designer and suddenly I needed to set one of this property. Then I took a look at the code and saw that the designer added a function InitializeComponent() and did the setting of the property there. Couldn't the property be set in the Form's constructor? And where can I find some docs on InitializeComponent() cause I looked at MSDN and couldn't find any. Any advice is greatly appreciated.
Regards
|
|
|
|
|
Of course you can set the properties in the constructor. I bet the VS designer just creates an "InitializeComponents" method so it can better keep track of the changes made directly through the designer.
That's why the designer can get confused if you modify the "InitializeComponents" section too much.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
But is this function automatically called? Because I cannot see any point where it is called.
|
|
|
|
|
Take a closer look at the Form() constructor
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hello Dear...
InitializeComponent() Is not a special thing ! This is a common function. It will call in Constructor.You can move all codes in this function to the constructor directely ! But You can't change this codes in designer ! Designer (VS.NET) Protects this portion of codes.If you change some codes in this area,Designer will reproduce theme at each rebuild.
I hope this was helpful for you,
Bye
|
|
|
|
|
Thanks a lot
|
|
|
|
|
Hi all,
I want to save the sender (object) or the information comming from th controls into an array. How to do that ?
object arr = new object[100];
void xyz_method (object sender, System.EventArgs e)
{
arr[i] = sender; // that didn't work
}
Thank's
regards
Frank
|
|
|
|
|
You have declared arr to be an object rather than an array of objects. That will make arr reference to the array rather than being the array. To use the array you would have to cast arr as being a reference to an array of objects:
((object[])arr)[i] = sender;
Instead, declare arr as an array:
object[] arr = new object[100];
Have you assigned a value to the variable i?
---
b { font-weight: normal; }
|
|
|
|
|
Why didn't that work? That aside, I'd suggest using an ArrayList, as hardcoding the array size as 100 is not a good idea.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi!
Do you know a Documentation or a good book? I want to write an eventhandler which catchs events, if a user writes a new date in the calendar or deletes some dates.
I need an example or something else!
Thanks!
|
|
|
|
|
Hi
I'm trying to execute some code after a dialog is initially displayed (but before the user has control), but I can't find an event that is triggered when this happens. What I'm trying to do is simulate a button click when certain initial conditions exist, but all the events I have tried (such as Activate) don't update the display until after the code has finished executing, and as this takes a relatively long time I need it to show and update my progress bar.
Can anyone help?
TIA
Ian.
|
|
|
|
|
Hi!
The event you're looking for is probably the Load event.
But no matter which event you choose, your GUI will usually not update inside a long-running action unless you call Application.DoEvents() to allow Paint events (and all others) to get a chance to execute.
Regards,
mav
|
|
|
|
|
Hi mav
Thanks for the response - I've tried using the Load event, and I was already using Application.DoEvents() in a couple of places, but even if I put them in the loops I still didn't see any part of the dialog until it had finished processing. However, I've now put in a call to Show() before the processing starts, and this seems to have done the trick!
Regards
Ian.
|
|
|
|
|
Hi, I have a little function for stripping the last part of an url using regular expressions. I did construct the expression in Expresso and have tried it on regexlib.com (http://www.regexlib.com/RETester.aspx). Works beautifully exept in my C# code! Can anyone see what I'm doing wrong.
<br />
private String stripFromUrl( string url )<br />
{<br />
String stripUrlPattern = "(?<fixedUrl>.+(?<=/))";<br />
Regex r = new Regex(stripUrlPattern, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);<br />
string stripurl = r.Replace(url, "${fixedUrl}");<br />
return stripurl;<br />
}<br />
The problem is that the string does not change at all. It just returns the string unchanged!
Please help!
|
|
|
|
|
|
From what I can tell from the documentation, named matches is not supported.
Try using the pattern "(.+(?<=/))" and use the index of the match in the replace: "$1".
---
b { font-weight: normal; }
|
|
|
|