Hi,
I want to declare objects that several source files can use.(similar to C++ extern storage class specifier ). I know that I can pass ref to every single object(winforms) will do but I was woundering is there any other work around ?
Using static class members I can share the variables but can't share the objects ? Please advice.
Thanks,
Sekhar
6 2036
Hi,
I want to declare objects that several source files can use.(similar to C++ extern storage class specifier ). I know that I can pass ref to every single object(winforms) will do but I was woundering is there any other work around ?
Using static class members I can share the variables but can't share the objects ? Please advice.
Thanks,
Sekhar
What do you mean by "can share the variables but can't share the objects "? The variables point to objects so if you can share the variables, you can share the objects.
What do you mean by "can share the variables but can't share the objects "? The variables point to objects so if you can share the variables, you can share the objects.
Thanks for your reply.When you are making a int or string as member of that class then you can easily share those using static but when an object is the class member variable then you can't share it that way. So I was looking something to share the object across the project.
Thanks for your reply.When you are making a int or string as member of that class then you can easily share those using static but when an object is the class member variable then you can't share it that way. So I was looking something to share the object across the project.
But strings and ints are objects as well. If you can share strings then you can share any object in the same way.
Maybe I didn't understand your question.
Thanks for your reply.When you are making a int or string as member of that class then you can easily share those using static but when an object is the class member variable then you can't share it that way. So I was looking something to share the object across the project.
If I understand you correctly I think you need is something like Singleton. If you're unfamiliar the design pattern, google it :)
What was wrong with static classes? -
public static class myglobals
-
{
-
//both of these are available for full use by other classes
-
public static int myTimeout=30;
-
public static Socket mysocket=null;
-
-
//available for use by other classes
-
public static int SomeFunction(int val)
-
{
-
return SomeHelperFunction(val)/2;
-
}
-
-
//this function is not available to other classes, but can be used by other
-
//members of the "myglobals" class
-
private static int SomeHelperFunction(int a)
-
{
-
if (a%2==0)
-
{
-
a=a+1;
-
}
-
return a;
-
}
-
}
-
If I understand you correctly I think you need is something like Singleton. If you're unfamiliar the design pattern, google it :)
That's if they want only one instance of that object and want to prevent creation of objects of that type once one has been created.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mervin Williams |
last post by:
I am using Infragistics UltraWebTab (a tab folder control for ASP.NET). My
tab folder control will include five tab pages with a separate web form on
each, and these web forms will share data.
...
|
by: Mervin Williams |
last post by:
I am using Infragistics UltraWebTab (a tab folder control for ASP.NET). My
tab folder control will include five tab pages with a separate web form on
each, and these web forms will share data.
...
|
by: Mervin Williams |
last post by:
I am using Infragistics UltraWebTab (a tab folder control for ASP.NET). My
tab folder control will include five tab pages with a separate web form on
each, and these web forms will share data.
...
|
by: Mervin Williams |
last post by:
I am using Infragistics UltraWebTab (a tab folder control for ASP.NET). My
tab folder control will include five tab pages with a separate web form on
each, and these web forms will share data.
...
|
by: bytesFlast |
last post by:
Hi all,
I would like to know what performance difference can arise if I use separate SQLConnection objects on each Form of a Multi-Form Windows .NET Application and a Single Common/Global SQL...
|
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: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
| |