Hi,
I have a class which all its attributes, properties and
methods are static.
However, I want a method to return an object that should
be non-static.
Is that possible?
thx,
Pascal 10 6328
Hi,
That's perfectly possible and is, for example, used in implementation of the
Singleton design pattern when a static property returns an instance of the
same class.
--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today! http://www.x-unity.net/teststudio.aspx
"Paschalis Pagonidis" <an*******@discussions.microsoft.com> wrote in message
news:4a****************************@phx.gbl... Hi,
I have a class which all its attributes, properties and methods are static.
However, I want a method to return an object that should be non-static.
Is that possible?
thx, Pascal
Paschalis Pagonidis <an*******@discussions.microsoft.com> wrote: I have a class which all its attributes, properties and methods are static.
However, I want a method to return an object that should be non-static.
Is that possible?
Objects themselves aren't static or non-static - the concept just
doesn't apply. Could you give more details about what you're trying to
do?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi Dmitriy,
can you give me an example?
for example:
public class MyClass
{
public static object CreateObject()
{
// I want obj to be non-static
object obj = new object();
return obj;
}
thanks,
Pascal -----Original Message----- Hi,
That's perfectly possible and is, for example, used in
implementation of theSingleton design pattern when a static property returns
an instance of thesame class.
-- Sincerely, Dmitriy Lapshin [C# / .NET MVP] Bring the power of unit testing to the VS .NET IDE today! http://www.x-unity.net/teststudio.aspx
"Paschalis Pagonidis"
<an*******@discussions.microsoft.com> wrote in messagenews:4a****************************@phx.gbl... Hi,
I have a class which all its attributes, properties and methods are static.
However, I want a method to return an object that should be non-static.
Is that possible?
thx, Pascal
.
I have a Database class that manages all database related
functionality.
For example instead of initializing SqlDataReader
variables each time in my whole project, I use commands
such as the following:
SqlDataReader data = Database.Execute
("MyStoredProc", "MyParams");
Database class has a static Connection variable which is
used in all forms. Furthermore all Database
constructors/properties/attributes/methods are static.
My problem is that the Execute command returns a static
SqlDataReader object, so I cannot re-execute a sql connand
inside a data.Read() loop:
while (data.Read())
{
data2 = Database.Execute(...); // <-- runtime error
occurs because data is already open.
}
data.Close();
// now that I closed data I can execute again...
thanks,
Pascal -----Original Message----- Paschalis Pagonidis <an*******@discussions.microsoft.com>
wrote: I have a class which all its attributes, properties and methods are static.
However, I want a method to return an object that
should be non-static.
Is that possible?
Objects themselves aren't static or non-static - the
concept justdoesn't apply. Could you give more details about what
you're trying todo?
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too .
> My problem is that the Execute command returns a static SqlDataReader object, so I cannot re-execute a sql connand inside a data.Read() loop:
no that is not your problem. like Jon said, there is NO such thing as an
object being static. There is absolutely no difference between a DataReader
returned from a static method vs. an instance method. your problem is
probably that DataReader keeps the underlying connection tied up to fetch
data, you'd have to use a second connection to execute another command.
this is also a quite expensive way of doing things, you should look into
joins to get all the data in one go if possible, rather than keep going back
to the database. or use disconnected dataset rather than having a datareader
tying up the connection for a prolonged period of time. -----Original Message----- My problem is that the Execute command returns a static SqlDataReader object, so I cannot re-execute a sql
connand inside a data.Read() loop:
no that is not your problem. like Jon said, there is NO
such thing as anobject being static. There is absolutely no difference
between a DataReaderreturned from a static method vs. an instance method.
your problem isprobably that DataReader keeps the underlying connection
tied up to fetchdata, you'd have to use a second connection to execute
another command. this is also a quite expensive way of doing things, you
should look intojoins to get all the data in one go if possible, rather
than keep going backto the database. or use disconnected dataset rather than
having a datareadertying up the connection for a prolonged period of time. .
thanks Daniel,
I think the most appropriate way (and less "expensive" in
terms of code changes) is to use disconnected datasets.
Paschalis Pagonidis <an*******@discussions.microsoft.com> wrote: I have a Database class that manages all database related functionality.
For example instead of initializing SqlDataReader variables each time in my whole project, I use commands such as the following:
SqlDataReader data = Database.Execute ("MyStoredProc", "MyParams");
Database class has a static Connection variable which is used in all forms.
That sounds like a bad idea. Connection pooling should be used to
handle this - I suspect getting rid of this will help you a great deal.
Furthermore all Database constructors/properties/attributes/methods are static.
My problem is that the Execute command returns a static SqlDataReader object
As I said before, an object isn't static or non-static. What do you
mean by the above?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Paschalis Pagonidis <an*******@discussions.microsoft.com> wrote: I have a Database class that manages all database related functionality.
For example instead of initializing SqlDataReader variables each time in my whole project, I use commands such as the following:
SqlDataReader data = Database.Execute ("MyStoredProc", "MyParams");
Database class has a static Connection variable which is used in all forms.
That sounds like a bad idea. Connection pooling should be used to
handle this - I suspect getting rid of this will help you a great deal.
Furthermore all Database constructors/properties/attributes/methods are static.
My problem is that the Execute command returns a static SqlDataReader object
As I said before, an object isn't static or non-static. What do you
mean by the above?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Phil Powell |
last post by:
My first time working with a PHP class, and after 6 hours of working out the
kinks I am unable to return a value from the class, so now I appeal to the
general audience what on earth did I do wrong...
|
by: Peter Meier |
last post by:
Hello everybody,
Stroustrup says he prefer's to declare operators, which do not do anything
on the class itself global. Does anybody know the reason for that?
Any advantages/disadvantages?
...
|
by: Jon Slaughter |
last post by:
I have a class that is basicaly duplicated throughout several files with
only members names changing according to the class name yet with virtually
the exact same coding going on.
e.g.
class...
|
by: baibaichen |
last post by:
i have written some code to verify how to disable slicing copy
according C++ Gotchas item 30
the follow is my class hierarchy, and note that B is abstract class!!
class B
{
public:
explicit...
|
by: vilarneto |
last post by:
Hello everyone,
I'm facing a particular situation about template class derivation.
The subject is old -- deriving a non-template class from a template
base class -- but my problem is that the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |