|
I got a question.
i am new in this things so
How do you get to the properties of een instance in an arraylist.
And it can be different kind of objects in the arraylist.
|
|
|
|
|
I cannot get your first question.
Arraylist can hold any kind of object. But for a particular instance, it should hold the same kind of object, ie., if you are keeping a string, you have to keep only strings, or if it is integer, you have to keep only integer.
Pradipta Basu
|
|
|
|
|
example
object motor()
object window()
Arraylist carParts
carParts.add(motor)
carParts.add(window)
now i wanna get to the properties of the objects motor and winow in carParts.
I wanna change value in those objects.
|
|
|
|
|
foreach(object part in carParts)
{
if(part is motor)
(part as motor).Cylinders = 12;
if(part is window)
(part as window).Electric = true;
}
Cast it to access the properties.
Or store the object to a new variable.
For instance:
Motor newMotor = null;
if(part is Motor)
newMotor = (part as Motor);
if(newMotor != null)
{
}
-Larantz-
|
|
|
|
|
or, without looking up type of object twice:
Motor newMotor = null;
if((newMotor = part as Motor) != null)
{
}
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
or, without the confusing assignment-and-cast-plus-equality-in-one
Motor newMotor = myArrayList[0] as Motor;<br />
if(newMotor != null)<br />
{<br />
<br />
}
|
|
|
|
|
IMHO it's just about as confusing as ternary operator.
btw, I don't see why would you comment what standart C# operator as does?? Oh wait, maybe because from
... some lines...
if(newMotor != null)
{
}
it's not immediately clear that you are not testing for null, but for type of object...
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
AS is just a no-exception cast. If the cast object is not of the casted type it returns null. Perfect if you want to cast and read a property.
|
|
|
|
|
CP ate my response
I know what as *operator* does, thank you. However I am missing your point.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
Hi there,
Anyone please tell me how to code to extract and compress .grf files as done by a program called GRF Tool. I found source code for the app but it was written in C++. I would like to know how to do so using C#. If anyone has any resource, please kindly provide it to me.
Thank you very much.
KiT
|
|
|
|
|
Hi Guys
I am relative new to Visual Studio... I'm about to do some calculations on my data and I was wondering if anybody can tell me the difference between choosing a Windows application or Console application when starting a project and what is the difference. Seems to me, to be easier to implement my algorithms in a console, because it is possible to get the data output in the commando-prompt (don't know how to do this in an application) and later on when designing the GUI I could change it over to an application, is this possible..?
Thanks in advance
AL
|
|
|
|
|
Not good design. That was applicable if the GUI would take a lot of programming, but now in C# all you usually do is drag/drop.
you want to display your output. It could be as easy as:
MessageBox.Show(MyOutputString);
or
MessageBox.Show(MyOutputInt.ToString());
Another way is to show it in a TextBox control:
MyTextBox.Text = MyOutputString;
You usually make a consol application when you don't need a user interface. e.g. a command line tool. If you will need a user interface, you should start a windows application from the beginning. If you don't know how to make a user interface in C#, learning it would be as easy as reading a comic book. Either grab a book, or screw thing up yourself with the designer till you get it right -I don't think it would be that way-. You can even download some free video tutorials on that from the net.
Regards
|
|
|
|
|
ComCoderCsharp wrote: Windows application or Console application
There is no major difference apart from the fact that in a Console application the console is displayed. In a windows one you can write stuff to the console (standard input / output / error) but nothing will be displayed or read.
ComCoderCsharp wrote: Seems to me, to be easier to implement my algorithms in a console
It doesn't really matter, displaying the data initially might be easier with a console.
ComCoderCsharp wrote: (don't know how to do this in an application)
The simplest solution would be to drop a textbox onto the form and append data to that using the TextBox.AppendText method.
ComCoderCsharp wrote: later on when designing the GUI I could change it over to an application, is this possible..?
Yes, just open the property pages and change the output type to Windows Application rather than console, all this does is change a command-line option when calling the C# compiler.
I have no idea what I just said. But my intentions were sincere.
|
|
|
|
|
A Console Application shows the console window while a Windows Application does not.
Both a Console Application and a Windows Application can open forms - so you could always use a console application and output logging information on the console (if you don't like Debug.WriteLine). Unlike forms, the console window content will be visible even if your application is not responding.
For the release builds, you could then just switch to a Windows Application.
|
|
|
|
|
This really cleared things up - I think I will use an application and view tha data in a gui box
all the best
Al
|
|
|
|
|
I have File-Exit Menu. In this menu I want to invoke FormClosingEvent. Please tell me how can call that event from From File-Exit Menu. I dont know what to write in enum CloseReason.
<br />
private void FileExit_Click(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
<br />
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)<br />
{<br />
<br />
if (dirty == true)<br />
{<br />
DialogResult res = SaveDialog();<br />
if (res == DialogResult.Yes)<br />
{<br />
SaveFile();<br />
e.Cancel = false;<br />
}<br />
if (res == DialogResult.No)<br />
{<br />
<br />
e.Cancel = false;<br />
}<br />
if (res == DialogResult.Cancel)<br />
{<br />
e.Cancel = true;<br />
<br />
}<br />
<br />
}<br />
}<br />
<br />
|
|
|
|
|
Call Close method of your main form.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank u.
FormClosedEventArgs ev = new FormClosedEventArgs(/*??? */);
MainForm_FormClosed(sender, ev);
Please tell me how can i call? What to write in argument, wat to write in CloseReason?
|
|
|
|
|
try one of these:
myMainForm.Close();
Close(); // inside main form class
Application.Exit();
Luc Pattyn
|
|
|
|
|
oooh very thanks.
I am still new with C# after 2 months
|
|
|
|
|
Just call Close on your File Exit handler. It will try to close the form, raising the Closing event in the process. If nothing cancels the closing, then you get the Closed event.
You don't have to call your Closing event handler manually.
|
|
|
|
|
I think you can send the win32AI message "WM_CLOSE" when the button is clicked like a function in win32 SDK "SendMessage()" function:
like this:
// define
[DllImport("User32.dll")]
public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
[DllImport("User32.dll")]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
const int WM_LBUTTONDOWN = 0x201;
const int WM_LBUTTONUP = 0x0202;
// sample, u should use spy++ to find windows class name and control class name
IntPtr hwndWin = FindWindow("TfrmMain", "window title");
if (hwndWin.Equals(IntPtr.Zero) == false)
{
IntPtr hwndBtn = FindWindowEx(hwndWin, IntPtr.Zero, "TButton", "control text");
if (hwndBtn.Equals(IntPtr.Zero) == false)
{
SendMessage(hwndBtn, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
SendMessage(hwndBtn, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
}
}
|
|
|
|
|
Hi everyone!
I have questions ...
How can i search treeNodes in an treeView using treeNode.Name property?
How can i highlight resultant nodes?
Please need some idea. Thanks.
|
|
|
|
|
h@s@n wrote: How can i search treeNodes in an treeView using treeNode.Name property?
You'd have to go through all nodes recursively.
h@s@n wrote: How can i highlight resultant nodes?
Call TreeNode.Select(), or TreeNode.Selected = true
Regards
|
|
|
|
|
Hi all,
I'd like to know how you make your application to support localizationand if you prefer to work with resources files and its namespace or you prefer to work with external xml files and tools (like gettext, ...). Why have you chosen your way?
Thanks in advance,
Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits
|
|
|
|