|
|
Right. Do I dare reach over to my bookshelf to get my BASIC-Plus and Turbo BASIC books?
|
|
|
|
|
Wow! I haven't seen good old BASIC like that for years! It's like an old friend enemy revisiting.
This is the C# forum in case you didn't realise. A rough mock up of your code in C# in case you want to give one of these new-fangled languages a try!
string name;
ConsoleKeyInfo emoState = new ConsoleKeyInfo();
string why;
Console.Write("What is your name? ");
name = Console.ReadLine();
Console.WriteLine(string.Format("Hello {0}, how are you doing today? ", name));
while (emoState.Key != ConsoleKey.G && emoState.Key != ConsoleKey.B)
{
Console.Write("Good (g) or bad (b)? ");
emoState = Console.ReadKey(false);
Console.WriteLine();
}
switch (emoState.Key)
{
case ConsoleKey.G:
Console.WriteLine("Thats good, tell me about it!");
Console.Write("Why is it a good day? ");
why = Console.ReadLine();
break;
default:
Console.WriteLine("Aww, im sorry.");
Console.Write("What was bad about your day? ");
why = Console.ReadLine();
break;
}
Console.Write("Press any key to exit...");
Console.Read();
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
hello,
I am confused about choosing a solution between two options and I am not sure which one is of more performance, would you please help me !!
Solution A
============
myClass A;
for(int i=0; i < aNumber; i++)
{
A = new myClass(i);
......................
}
Solution B
=============
for(int i=0; i < aNumber; i++)
{
myClass A = new myClass(i);
......................
}
|
|
|
|
|
The solution A is looking like my favorite, its reduced. For one thing whats it for that might change my mind
|
|
|
|
|
Hi,
your two code snippets will compile to the same IL instructions and run identically.
The only difference is in the scope of A; in solution A, A still has a value when the for loop exits (assuming aNumber is greater than zero); whereas in B, A is dead and burried when the loop exits.
modified on Thursday, December 11, 2008 7:46 PM
|
|
|
|
|
The second is better, it's more readable by far. It also limits the scope of the object, and if you don't need it outside the loop, that's a good thing.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Yeah, what they said, except B always looks like it'll waste cycles.
|
|
|
|
|
If you just need to run some stuff in A, then throw it away, maybe you should consider adding some kind of "reset" method to myClass which will probably be much faster than instantiating a new object again and again.
Just run a quick benchmark with
DateTime start = DateTime.Now;
for(int i=0; i < aNumber; i++)
{
myClass A = new myClass(i);
......................
}
DateTime end = DateTime.Now;
MessageBox.Show( ((TimeSpan)(end-start)).TotalMilliseconds );
|
|
|
|
|
That depends on how expensive the instantiation is.
A few months ago I spent some time working on a technique to keep using one static StringBuilder throughout a library of static methods;
clearing it before each use rather than instantiating (and re-extending as necessary).
In the case of StringBuilder, my technique wasn't worth the trouble.
And for quick benchmarks like that I now use a System.Diagnostics.Stopwatch
|
|
|
|
|
When I open the network connection from the control panel, I can see several connecton for differnt network interface. example "Local Area connection";
I want to get this connection name == "Local Area connection" == programatically. For local machine it is possible using NetworkInterface Class but I am trying to get it for a remote machine.
NetworkInterface class can not used for remote machine. I used WMI for remote machine connection configuration but I am able to get all related information for any interface but no property is found in Win32_NetworkAdapterConfiguration class which is directly related to my requirement. Caption, Name, and other property gives me some other information but not the thing I am looking for.
Any idea, hint will be helpful.
Thank you
|
|
|
|
|
Cant you just do a file load and put the file of the Local Area Connection into your program, ive dont that for my internet debugger thing :P that might i work, i might be able to help you though.
|
|
|
|
|
Patrick_N3WB1E wrote: Cant you just do a file load and put the file of the Local Area Connection into your program,
Uhhh...would you care to explain what you mean by this?? A "file load" to get an adapter name??
|
|
|
|
|
s196675m wrote: I used WMI for remote machine connection configuration but I am able to get all related information for any interface but no property is found in Win32_NetworkAdapterConfiguration class which is directly related to my requirement.
Did you look at the WMI Win32_NetworkAdapter class??
|
|
|
|
|
|
Yes, I did and I have found the property. Unfortunately I overlooked this property in my previous investigation.
The Property name is "NetConnectionID" of "Win32_NetworkAdapter" class.
Thank you
|
|
|
|
|
Using VS2008:
I have the following code
public class MyEventArgs : EventArgs
{
public MyEventArgs()
{
}
}
public partial class BaseForm : Form
{
public delegate void MyEventHandler(object sender, MyEventArgs e);
public event MyEventHandler MyEventFunction;
public BaseForm()
{
InitializeComponent();
}
}
public partial class JohnsForm : BaseForm
{
private void button1_Click(object sender, EventArgs e)
{
MyEventFunction(this, new MyEventArgsArgs());
}
}
Intellisense is telling me this:
The event BaseForm.MyEventFunction can only appear on the left hand side of += or -=
If I move the event declaration info the JohnsForm class, Intellisense decides it's okay. Of course the workaround for this is to create a function in the BaseForm class that raises the event and call that function from my derived class, but why do I have to do that?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Intellisense also states:
"(except when used from within the type 'yournamespace.BaseForm')"
Compiler Error CS0070[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Actually, I didn't try compiling it because Intellisense insisted it was screwed up. I just want to why it doesn't treat it like a normal class member.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: I just want to why it doesn't treat it like a normal class member.
By design, I suppose.
"...events are a special type of delegate that can only be invoked
from within the class that declared them. Derived classes cannot directly
invoke events that are declared within the base class"
How to: Raise Base Class Events in Derived Classes (C# Programming Guide)[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You can't raise an event (directly) from a derived class. (WTF?)
Write a method to wrap it.
protected void RaiseMyEventFunction
(
blah blah
)
{
if ( MyEventFunction != null )
{
MyEventFunction(this, new MyEventArgsArgs());
}
}
And call that instead, it's good practice anyway.
|
|
|
|
|
PIEBALDconsult wrote: You can't raise an event (directly) from a derived class. (WTF?)
I already know that (now), and I mentioned writing a function to do it in the base class. I just want to know why I can't raise an event in a derived class, and perhaps where the reason is explained.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Security, I guess, but I don't see it either.
|
|
|
|
|
I believe this is by design if you use the event keyword. I never use it, I just define a delegate and call it.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
You cannot call directly events of a base class from a child class
You must declare a protected (or other scope) method on the base class to handle that
If you dont want that quit the "event" keyword
public class MyEventArgs : EventArgs
{
public MyEventArgs()
{
}
}
public partial class BaseForm : Form
{
public delegate void MyEventHandler(object sender, MyEventArgs e);
public event MyEventHandler MyEventFunction;
public BaseForm()
{
InitializeComponent();
}
protected virtual void OnMyEventFunction(object sender, MyEventArgs e){
MyEventFunction(sender, e);
}
}
public partial class JohnsForm : BaseForm
{
private void button1_Click(object sender, EventArgs e)
{
OnMyEventFunction(this, new MyEventArgsArgs());
}
}
Saludos!!
____Juan
|
|
|
|