|
I have these pieces of code:
public class MyClass : System.Net.Sockets.TcpClient
public MyClass ()
{
MyProperty = new TcpClient ();
}
public TcpClient MyProperty {
get { return MyProperty; }
set { MyProperty = value; }
} And when I execute the following line of code I get a StackOverflow :
private MyClass myNewClass = new MyClass (); If I step through the execution, the program continually calls the set method of MyProperty until the StackOverflow occurs. Any help as to why this is occuring and how to fix it would be very appreciated.
Thanks!
- monrobot13
|
|
|
|
|
Think about it. Your class has a property named MyProperty. In the constructor, you set the value of that property. But the property setter recursively calls itself ("MyProperty = value;"). Instead, you need to declare a private variable _MyProperty, change the setter to "_MyProperty = value;" and the getter to "return _MyProperty;".
Sean Winstead
|
|
|
|
|
Or better yet...adhere to the design guidelines and do myProperty rather than _MyProperty.
any idiot
can write haiku you just stop
at seventeenth syl
-ThinkGeek Fortunes
|
|
|
|
|
Or better yet...adhere to the design guidelines and do myProperty rather than _MyProperty.
Thanks Where can I find the design guidelines?
Sean Winstead
|
|
|
|
|
You can find everything you need (including FxCop) here[^]
any idiot
can write haiku you just stop
at seventeenth syl
-ThinkGeek Fortunes
|
|
|
|
|
|
Thanks, I understand now. I falsely assumed that that part was taken care of automatically.
- monrobot13
|
|
|
|
|
I forgot what *=, += things do...
can somebody refresh my memory?
gracias.
SENOR EGG>
/\ |_ E X E GG
|
|
|
|
|
*= is the emoticon for a man with an afro.
+= is the emoticon for a person who wants to give a hug.
Sean Winstead
|
|
|
|
|
Seriously though,
x *= 5 is equivalent to x = x * 5
x += 5 is equivalent to x = x + 5
Sean Winstead
|
|
|
|
|
ahhhhhh it's all comming back to me....
shanks.
/\ |_ E X E GG
|
|
|
|
|
A+=1 is the equivelant of A=A+1 so I would say A*=3 is the same as A=A*3. I hope that refreshes you!
[Edit]Looks like someone beat me to it![/edit]
"We will thrive in the new environment, leaping across space and time, everywhere and nowhere, like air or radiation, redundant, self-replicating, and always evolving." -unspecified individual
|
|
|
|
|
can i know how to use StartCap and EndCap members of Brush class.i need to use LineCap or nt?can i have some sample code of how to create.thank you.can i do it like this way.
m_PenToDrawWith = new Pen(Color.Red);
m_PenToDrawWith.EndCap=System.Drawing.Drawing2D.LineCap.DiamondAnchor;
|
|
|
|
|
Is it possible to convert a string to an int in C#?
Thanks!
- monrobot13
|
|
|
|
|
There is an Int32.Parse(string) function, but it will throw an exception if the string is not an integer.
|
|
|
|
|
Convert.ToInt32(string str); as well
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
Here's the deal - I have two programs. One is a utility program used to create objects and serialize them to disk. The second program is the real application which, in time, will be able to deserialize these objects and use them.
When I serialize and deserialize within the utility program, I have no problems. However, when I try to deserialize within the main program, I get an error that looks like:
"Type is not resolved for member MyNameSpace.MyClass, MyNameSpace."
I was getting a different error earlier, but I was able to make it further by setting the assembly names to be the same in each program. Is that necesarry and the correct thing to do?
Storing code, roughly:
<br />
Stream myStream = File.OpenWrite(m_sFileName);<br />
if (myStream != null)<br />
{<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
formatter.Serialize(myStream, m_object);<br />
}<br />
Loading code for both programs, roughly:
<br />
if (myStream != null)<br />
{<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
m_object = (MyObject)formatter.Deserialize(myStream);<br />
myStream.Close();<br />
}<br />
Any help is appreciated!
Marcus Spitzmiller
"Why must life be so hard? Why must I fail at every attempt at masonry?" - Homer
|
|
|
|
|
Try to use the Binder property of the formatter. This interface can be used to search for types of different assemblies. Another solution is to put all the assemblies in the GAC.
|
|
|
|
|
Thanks Davide - I will try this out and get back to you.
Marcus Spitzmiller
"Why must life be so hard? Why must I fail at every attempt at masonry?" - Homer
|
|
|
|
|
Davide - I managed to work this out. Thanks for the help, but it turns out that I'm just not very familiar with the IDE yet. I had some references messed up, and once I straightened it out, it serialized with no problems, and no customizations.
Thanks again
Marcus Spitzmiller
"Why must life be so hard? Why must I fail at every attempt at masonry?" - Homer
|
|
|
|
|
Probably a dumb question, but does anyone know if it is possible to issue HLT instructions using C# ?
|
|
|
|
|
Please help...
I am trying to do something in a loop while letting the user press the keyboard when he/she sees something I put on screen. So I decided to time his/her response time using Form1_KeyDown.
But the problem is: when the user hits the key, the event seems to be queued or buffered. And I never got to the Form1_KeyDown code until the for loop is over.
Could anybody help?
Thanks
private void menuLoop_Click(object sender, System.EventArgs e)
{
for (int i=0; i< 100; i++)
{
//do something here
Console.WriteLine("Loop #{0}", i);
}
}
private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
long tick;
Win32.QueryPerformanceCounter(out tick);
Console.WriteLine("Current tick: {0}", tick);
}
|
|
|
|
|
private void menuLoop_Click(object sender, System.EventArgs e)
{
for (int i=0; i< 100; i++)
{
//do something here
Console.WriteLine("Loop #{0}", i);
Application.DoEvents();
}
}
Paul
And you run and you run to catch up with the sun, but it's sinking Racing around to come up behind you again The sun is the same in a relative way, but you're older Shorter of breath, one day closer to death - Pink Floyd, Time
|
|
|
|
|
Hello everyone,
The problem is simple:
in my class I obtained a type using reflection GetType.
Type t = Type.GetType(my_StringT);
NOW: how should I cast a variable to type obtained???
simple cast doesn't work...
Object my_NewType = (t) my_OldType; -> here the compiler told that
type or namespace 't' could not be found.
So, how should I use obtained type to cast my variable????
Thanks,
Don Miguel.
|
|
|
|
|
Don Miguel wrote:
So, how should I use obtained type to cast my variable????
You dont. This has riddled my mind a few times, but I have realise this is NEVER necessary.
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|