|
You have it backwards, constructor 1 is called before constructor 2, and 2 before 2.
You want:
class Foo {
public Foo() : this("sensibledefaultvalue") {}
public Foo(string arg1) : this(arg1, "otherdefaultvalue") {}
public Foo(string arg1, string arg2) {
}
}
Typically no code is ever added to the first two constructors with this style, they exist only to provide polymophism and default values.
-Blake
|
|
|
|
|
can u pls help me to explain..in what scenario's do we need to do such things???
i mean...is there any case where this is the only way out??
is this kinda stuff common??
never seen anything such as this in my life...
can u pls take some time to explain any such SCENARIOS where above code is DEFINETLY REQUIRED please????
tks a lot...
really appreciate you guys help...
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
"For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
John 3:16
"Therefore you also be ready, for the Son of Man is coming at an hour you do not expet."
Luke 12:40
|
|
|
|
|
It's never required, it is just the most convenient way to express a common idiom.
Often there are several possible optional values that you might accept to control the construction of your object. Equally often, you want to provide more convenient constructors that provide some reasonable default for some or all of those values.
You do this by writing the constructor once, taking all the arguments as parameters. Then you write empty constructors that take fewer arguments, provide the defaults, and pass the call off to the larger constructor.
-Blake
|
|
|
|
|
hi Mr.Blake...
your answer was a bit too technical for me and i didnt really get it....
would u kindly help me a bit more and gimme some links or explanation in simple words where can i use this kinda stuff and where do i need it??
tks a lot...
appreaciate your time and help
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
"For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
John 3:16
"Therefore you also be ready, for the Son of Man is coming at an hour you do not expet."
Luke 12:40
|
|
|
|
|
Another example:
You have a class which describes a task:
public class task {
public task(string name, DateTime date, int priority) {
//DoSomething
}
}
No someone really often creates those objects with Priority 2 but doesnt want to always pass this in. So we declare another constructor
public task(string name, DateTime date) : base(name, date, 2)
{
}
To quickly add tasks we want another constructor to create tasks with Priotity 2 and 'Today' as the date. So we declare another constructor:
public task(string name) : base(name, DateTime.Now)
{
}
Now you have the choice to call the full constructor with all possible arguments, or you just call one of the other constructors to decrease the writing. Another plus is, that you can change the default priority in one place.
Greetings Robert
|
|
|
|
|
Is it possible, using XML/SOAP web services, to perform a 3-way communication, namely, REQUEST, RESPONSE, and ACK?
Client sends the REQUEST, receives the RESPONSE, and send an ACK to the server to acknowledge the receive of the response.
If not, that could be a good project and/or subject of article, do you think?
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Hey,
How to turn off behaviour of TreeView control that if you double click on branch with children than it will expand/collapse? Overriding OnDoubleClick() doesn't work as some other event does collapse/expand.
|
|
|
|
|
I am assuming that the "OnDOubleClick" function you are talking about is a function you implemented as a callback in the parent window class, to process the NM_DBLCLK notification message from the tree control.
This message is sent to the parent window AFTER the tree control finishes its default processing.
You need to subclass the tree control and handle the WM_LBUTTONDBLCK message appropriately.
|
|
|
|
|
Solution de Uberness:
-----------------------------------------------
using System;
namespace UberControls
{
public class TreeViewNonExpanding : System.Windows.Forms.TreeView
{
private bool incomingDoubleClick = false;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch( m.Msg )
{
case 0x0203: // WM_LBUTTONDBLCLK
this.incomingDoubleClick = true;
break;
case 0x0202: // WM_LBUTTONUP
this.incomingDoubleClick = false;
break;
default:
break;
}
base.WndProc (ref m);
}
protected override void OnBeforeExpand(System.Windows.Forms.TreeViewCancelEventArgs e)
{
if( incomingDoubleClick == true )
e.Cancel = true;
base.OnBeforeExpand (e);
}
}
}
|
|
|
|
|
I have designed a .Net web service and the client is requesting a new web method to return the web service version number? My web service code consists of the following:
<br />
<WebMethod(Description:="Get Web Service Version Number.")> _<br />
Public Function GetVersion() As String<br />
Dim sValue As String<br />
sValue = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()<br />
Return sValue<br />
End Function<br />
The problem is this returns “0.0.0.0”. I have tried the following in the assembily.vb file with no luck:
<br />
'<Assembly: AssemblyVersion("1.0.*")> <br />
<Assembly: AssemblyVersion("*")> <br />
Can anyone tell me what I’m doing wrong.
Thanks,
Jason W.
|
|
|
|
|
The code you have should work perfectly. AssemblyVersion("*") isn't valid however. I actually got a compiler error when I tried to use it.
The asterisk in the default tells the compiler to automatically increment the version as you build..
1.0.4.3333
1.0.4.3334
...etc...
Use AssemblyVersion("1.0.*") or specify the full version ("1.0.0.0")
If you debug your web service, do you also see 0.0.0.0 returned to string sValue?
|
|
|
|
|
Now why didn’t that work the other day? It works now. Thanks for the help.
Jason W.
|
|
|
|
|
Hi!
The point is that while scrolling within a datagrid, sometimes the gridloses focus with no reason because I was just scrolling.The class below simply illustrates this(while scrolling you'll get a message)
Thank you in advance.
ps: I'm using vs.net 2003.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace test2k3
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dg;
private DataTable dt;
private System.Windows.Forms.Button button1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
dt = new DataTable();
DataColumn dc = new DataColumn("Nr");
dt.Columns.Add(dc);
for(int i = 0 ; i < 100; i++)
{
DataRow dr = dt.NewRow();
dr[0] = "row #"+i;
dt.Rows.Add(dr);
}
this.dg.DataSource = dt;
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.dg = new System.Windows.Forms.DataGrid();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dg)).BeginInit();
this.SuspendLayout();
//
// dg
//
this.dg.DataMember = "";
this.dg.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dg.Location = new System.Drawing.Point(24, 16);
this.dg.Name = "dg";
this.dg.Size = new System.Drawing.Size(160, 128);
this.dg.TabIndex = 0;
this.dg.Leave += new System.EventHandler(this.dg_Leave);
//
// button1
//
this.button1.Location = new System.Drawing.Point(232, 64);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 32);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(328, 173);
this.Controls.Add(this.button1);
this.Controls.Add(this.dg);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dg)).EndInit();
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void dg_Leave(object sender, System.EventArgs e)
{
MessageBox.Show("You haven't leaved the grid.You've been just scrolling!","Is This A Bug?");
}
}
|
|
|
|
|
More specifically, the .Leave event is fired when the currently selected cell is scrolled out of view (up or down). Curiously, no Enter event is fired when it is scrolled back in view but a Leave *will* be fired again if you continue scrolling. And in neither case is Got/LostFocus() fired.
I don't usually like to call things bugs in frameworks like this as I usually find the reason or solution as soon as I do.
Depending on what you want to do when focus is lost and gained, I think you can find a pattern of events to identify this situation.
For example, clicking between cells causes: GotFocus, CurrentCellChanged, LostFocus
However in the scrolling scenario: Leave, Validating, Validated
|
|
|
|
|
am i write to say that .NET does not provide any library to directly access any system device. if yes, can anyone tell me how can i access hardware devices using WMI (Windows Management Instrumentation). a short example would be nice.
|
|
|
|
|
before asking this kind of question why don;t you search the site!!!!
just type WMI into the textbox at the top of the page...
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
actually i did but all in vain. every example posted in WMI articles are not about peripherals like sound devices, video cameras or even scanners....
i thought maybe anyone have had worked in this particular case!
|
|
|
|
|
In version 6.0 I could right click and delete, now I can only add????
|
|
|
|
|
To be honest, I never use the Class Viewer - working directly in Solution Explorer. From Solution Explorer, you can delete files, and assuming you follow standard practice of 1 class per file, this should do the same thing.
|
|
|
|
|
Thanks, I finally saw that. The "file view" magically re-appeared.
|
|
|
|
|
I have application with header and detail. I browse the data both with datagrid. In datagrid parent i have some trouble, it is display plus (+) sign because the datasource for this grid have relation. I dont want to remove this relation. How to invisible this sign Thx.
|
|
|
|
|
Does anyone know of a way to dynamically determine which server to use a web service from.
I basically want to be able to change a registry setting and switch web servers should one fail.
Think .NET Reflection is likely to a part of the solution??
Thanks in advance,
Andrew
|
|
|
|
|
There is a Url property to a Web Service.
localhost.Service1 tService = new localhost.Service1();
tService.Url = "http://www.GoThere.com/Service1/";
|
|
|
|
|
How to shutdown windows from vb .net application thx
|
|
|
|
|
You can use the ExitWindowsEx[^] method, but remember, on Win2000/XP you'll need extra privileges to use it.
|
|
|
|