|
My C# book reads:
In this example, the two-parameter constructor executes before any code in the body of the one-parameter constructor (though in this particular case, since there is no code in the body of the one-parameter con-structor, it makes no difference).
By following through the code it seems that the one-parameter constructor is called first, which in turn calls the two-parameter constructor, so, is this an error, or do you think it might have another meaning?
J.
using System;
using TestConsole.TestClasses;
namespace TestConsole.ConsoleCmds
{
public class TestOne
{
public static void Main()
{
Car myCar = new Car("Proton Persona");
}
}
}
namespace TestConsole.TestClasses
{
class Car
{
private string description;
private uint nWheels;
public Car(string model, uint nWheels)
{
this.description = description;
this.nWheels = nWheels;
}
public Car(string model) : this(model, 4) { }
}
}
Jon
|
|
|
|
|
Hi Jon,
it is the one-parm constructor that gets invoked first, but it is the body of
the 2-parm one that executes before the (empty) body of the 1-parm constructor.
Same prder as the code that says: Car(model) needs "this(model,4)" before it does the "{ }".
BTW if you use <pre>some code</pre> you can show code snippets
that preserve their formatting (mainly indentation). That would be much more readable.
On the other hand, if your post contains special characters (especially <)
they get eaten by the HTML interpreter, then you better would check the "ignore HTML tags"
checkbox below the textbox (but then thr pre command will no longer work either).
|
|
|
|
|
Thanks for your reply.... you mean this is readable?
class Car
{
private string description;
private uint nWheels;
public Car(string model, uint nWheels)
{
this.description = description;
this.nWheels = nWheels;
}
public Car(string model) : this(model, 4) { }
}
Jon
|
|
|
|
|
Hi Jon, you're welcome. Yes, it is much more readable like that.
|
|
|
|
|
Luc Pattyn wrote: if you use
some code you can show code snippets
that preserve their formatting
If I may add, I like to put <code> and </code> tags inside the <pre> tags. Just colors it up nice
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
I'll try that next time; I once did just <code> and was not happy about the result. Thanks.
|
|
|
|
|
<code> by itself doesn't do much, at least when it comes to preserving indentation.
Here is a simple example of how I do it...
private bool foo(int x)
{
if ( x < 0 )
return true;
else
return false;
}
I like it because it makes the code stand out a bit better.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Oh, it's a dark red color?
I made a test message with and without <code>, and I couldn't see any difference at all.
I made a screen dump and pasted in photoshop, where I could put them in different layers on top of each other so that I could flip between them and see exactly what the difference was, but there was no difference.
Or was it? Maybe there was a slight difference? I had to use the eyedropper to get the color of the text to tell what the difference was...
---
single minded; short sighted; long gone;
|
|
|
|
|
Are you using <code> before or after the <pre> tag? It will make a difference.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
The code tag is inside the pre tag.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi Paul,
the problem with your examples is they show result, not source.
Anyway, I did my little experiment and I observed:
PRE gives non-proportional font, pink background, and preservation of spaces and tabs
CODE gives non-proportional font, red foreground (hardly noticable), and when copying several
lines then newlines are lost.
for both: the optional "lang=cs" does not do anything.
My conclusion:
- I will continue to use PRE without CODE for blocks of code, (so one can copy them easily)
- I will occasionally use CODE without PRE inside a text alinea to quote a piece of
code that fits on a single line (so the newline-not-copied problem isnt relevant).
Does this match your view on things ?
Regards
|
|
|
|
|
This whole thing is strange. I just did <code><pre> and it shows orange background with black text, which is what I think Guffa was talking about; then doing <pre><code> yields orange background with red text.
Luc Pattyn wrote: Does this match your view on things ?
I see your point, and good case you've made with when to use <pre> and <code>.
I think the "lang=cs" is for articles, not 100% sure. as far as new lines go, I haven't seen anything go awry. I tried FF, IE, and Safari and can't really draw a conclusion on my configuration
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Paul Conrad wrote: I think the "lang=cs" is for articles, not 100% sure
Yes, I got it from the article manual, but decided to give it a try anyway. Would look
great on discussion forum too...
OK, I am taking this opportunity to add some more test cases:
public void nihil(int a) {
if (a!=0) throw new Exception("Not zero");
}
public void pre(int a) {
if (a!=0) throw new Exception("Not zero");
}
<br />
public void code(int a) {<br />
if (a!=0) throw new Exception("Not zero");<br />
}<br />
public void precode(int a) {
if (a!=0) throw new Exception("Not zero");
}
public void codepre(int a) {
if (a!=0) throw new Exception("Not zero");
}
|
|
|
|
|
Same stuff with "ignore HTML tags":
<blockquote class="FQ"><div class="FQA">Paul Conrad wrote:</div>I think the "lang=cs" is for articles, not 100% sure</blockquote>
Yes, I got it from the article manual, but decided to give it a try anyway. Would look
great on discussion forum too...
OK, I am taking this opportunity to add some more test cases:
public void nihil(int a) {
if (a!=0) throw new Exception("Not zero");
}
<pre>
public void pre(int a) {
if (a!=0) throw new Exception("Not zero");
}
</pre>
<code>
public void code(int a) {
if (a!=0) throw new Exception("Not zero");
}
</code>
<pre><code>
public void precode(int a) {
if (a!=0) throw new Exception("Not zero");
}
</code></pre>
<code><pre>
public void codepre(int a) {
if (a!=0) throw new Exception("Not zero");
}
</pre></code>
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] }
catch { [Google] }
|
|
|
|
|
See my post I posted at the same time about the CPSyntax. On my laptop anything you have inside the code tags are showing up white/light blue alternating lines. Anything in just the pre tag by itself is showing up with light blue background/red text...
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Paul Conrad wrote: I just did
and it shows orange background with black text, which is what I think Guffa was talking about
Nope.
---
single minded; short sighted; long gone;
|
|
|
|
|
What do you get? I think Luc and I are trying to figure it out right now. We have have to ask Chris
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
If you ask Chris for some clarification and improvements, I'll second that.
Possible improvements:
support copy-with-newlines after code tag;
syntax coloring;
ignore all tags inside pre or code tag (so < and > remain intact inside code).
BTW: on IE6 (the only one I use) I dont see any difference between pre-code and code-pre.
Regards
|
|
|
|
|
Luc Pattyn wrote: IE6
Hmmm, I have IE7, haven't used IE6 since IE7 came out.
The ideas you've mentioned for improvement could work
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Paul Conrad wrote: I have IE7, haven't used IE6 since IE7 came out
I am happy with my current set of security holes. Dont need new features/creatures.
|
|
|
|
|
Luc Pattyn wrote: I am happy with my current set of security holes. Dont need new features/creatures.
I've got too much on this machine, nothing terrible or evil, just loads of different 30 day trial tools that need dumping. Might be time for some housecleaning
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Just fired up my laptop which has the CPSyntax Greasemonkey script and it shows alternating lines of white/light blue in the code.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
I am developing a screen saver in C#. However, I am stuck at one point. How can I embed resources in the src that will be build ? and any information how the standard screen savers store the resources ?
Thanks.
Please note images are to loaded at run-time which I want to embed in the src file, that the application will create.
-- modified at 7:57 Sunday 22nd July, 2007
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg."
- Bjarne Stroustrup
|
|
|
|
|
Hi,
there are several good articles on screensavers available on CodeProject.
you can include resources (images, icons, ...) in your exe by:
- adding their file to your project (I typically add a "resources" folder in the Solution Explorer pane)
- setting its "Build Action" to "Embedded Resource"
- adding some code to access the resource; I cant remember what exactly, so I let Visual
Designer use my resource (e.g. as an image for a picturebox, an icon for the main form),
then look at the code it generated, and copy/paste/modify that
I see no reason why screensavers would handle resources any different than other apps do.
|
|
|
|
|
Thanks for your response.
I am adding the images at run-time.Any help on this. I have got to know about ResourceWriter which creates a satellite dll. What I need is a single scr file, which has the resources embedded.
So any help on making the resource embedded in an exe at run-time ? Do I need to compile another exe(scr) at run-time and embed those images in the new exe(scr)?
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg."
- Bjarne Stroustrup
|
|
|
|