|
Simple: the constructor may do something that affects non-transient storage.
For example, it may insert the new object into the appropriate databases. That the object is not needed again by the code that creates it is irrelevant to the system.
It doesn't need a warning, any more than ignoring the return value from any other method call does:
private int MyMethod(int i)
{
i = i * 2;
Console.WriteLine (i);
return i;
}
...
MyMethod(6);
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Which "return" did you forget? The return in "return base.CreateMessageSource(...)", or do you think of a return before "new TransitionPointerMessageSource(...)"?
In the first case, I'd expect a compiler error, in the last case no warning or error at all, as others explained already.
|
|
|
|
|
As others have said, a constructor is just a method and can reasonably do things other than simply initialise the object. Whether you consider them good practice or not, there are uses for this: for example, the constructor could register the instance in some local storage to make the object non-transient, it could transmit itself over a network connection or persist itself to file, it could modify static state or the state of the objects passed into it, as well as having other side effects.
|
|
|
|
|
Ok, I'm pretty sure I didn't learn anything from everyone's responses (I do know about side effects), except maybe that people seem to have a difference sense of what is good programming practice than I. To me, calling a constructor to achieve side effects seems obscure at best. I guess I'm just glad I don't have to try to read code written that way. But, as someone said, perhaps it would be presumptuous of the compiler to warn about that.
|
|
|
|
|
personally, i made it one time, to call a static constructor of one type that i was implementing, test reasons, code that never made it to production...
in my case the static constructor check for a file, if it doesn't exists, they create it with default values, but in that test i wasn't able to call any other method because they made changes to the file and i was looking for the default one...
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
|
|
|
|
|
Good Evening! I try to realize the search on a particular sheet Excel workbook.
I do late binding with a book as:
using Excel = Microsoft.Office.Interop.Excel;
private void button1_Click(object sender, EventArgs e)
{
excelapp = new Excel.Application();
excelapp.Workbooks.Open(@"C:\4.xls", Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
Next, I enter into textbox1, for example, the word TXTMessage, this means that the need to look at the sheet of TXT, and textbox2 - the search term in the third column (for example).
How to implement search?
Please, help me if you can.
|
|
|
|
|
I don't know, I've never used Microsoft.Office.Interop.Excel, I use ADO.net with an OleDb connection to ACE for Excel and Access, so I just use an SQL query.
What are you trying to accomplish?
|
|
|
|
|
i try just find essential record in the list
|
|
|
|
|
Then I recommend ADO.net -- do you need some pointers on that?
|
|
|
|
|
Thanks, but i have to use mechanism of the late binding.
|
|
|
|
|
Ummm... oookaaay... you can do that with ADO.net; I generally write utilities that take command-line parameters, like what database to connect to, what table to query, etc.
What are you trying to accomplish?
|
|
|
|
|
I'm trying to make the system of authentication
|
|
|
|
|
Do You know how to access list by name?
|
|
|
|
|
What list? The worksheet name? The column name?
|
|
|
|
|
This is worksheet, sorry.
|
|
|
|
|
|
Your excelapp/workbook will have a collection of worksheets which you can iterate.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I know, but I need to refer to the worksheets by name.
How I can do it?
|
|
|
|
|
I'm pretty sure the indexer will accept a string as well as an integer Workbook.Worksheet["SheetName"]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Could you show an example refer to worksheet and search for an arbitrary column? Because I never did it. If you can. Thanks.
|
|
|
|
|
bonjour,
"""pour le moment je suis entrain de développer une application qui enregistre le son( sous forme numérique) entré par une carte électronique dés le port // .alors j'ai qlq questions a vous posé .
1) comment enregistrer du son qui va être sous forme numérique avec une application c # sur une base de données (sql server) ?
2 ) aussi comment lire ce son enregistrer (Sous forme numérique) dés la base de données ???
merci d'avance"""""
|
|
|
|
|
Je suis désolé, mais c'est un site anglophone. Vous allez vous tenir plus de chance d'obtenir une réponse si vous traduisez votre question en anglais.
The Google translation:
""" "for now I am trying to develop an application that records audio (digital form) entered into an electronic card dice / / port. so I QLQ questions you asked.
1) how to record sound which will be in digital form with a C # implementation of a database (sql server)?
2) how to read it as his record (In digital form) dice the database??
thank you in advance "" "" ""
|
|
|
|
|
thank's man don't worry i speak english too
|
|
|
|
|
Je ne habbello Francais. You'll find that the documentation is in English, the community is English, and that hence, the preferred language is English.
What do you want help with exactly? Recording sounds as binary, saving binary to a database, or the whole shebang?
Bastard Programmer from Hell
|
|
|
|
|
Thank's sir for your answer
by the way the sound that will enter by the Parallel Port as Digital Data so i wanna saving binary to a database with c sharp application .
how can i do that ??
|
|
|
|