473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Object Sharing across forms in C#

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
Sep 13 '07 #1
6 2036
r035198x
13,262 8TB
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.
Sep 13 '07 #2
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.
Sep 13 '07 #3
r035198x
13,262 8TB
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.
Sep 14 '07 #4
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 :)
Sep 14 '07 #5
Plater
7,872 Expert 4TB
What was wrong with static classes?
Expand|Select|Wrap|Line Numbers
  1. public static class myglobals
  2. {
  3.    //both of these are available for full use by other classes
  4.    public static int myTimeout=30;
  5.    public static Socket mysocket=null;
  6.  
  7.    //available for use by other classes
  8.    public static int SomeFunction(int val)
  9.    {
  10.       return SomeHelperFunction(val)/2;
  11.    }
  12.  
  13. //this function is not available to other classes, but can be used by other 
  14. //members of the "myglobals" class
  15.    private static int SomeHelperFunction(int a)
  16.    {
  17.       if (a%2==0)
  18.       {
  19.          a=a+1;
  20.       }
  21.       return a;
  22.    }
  23. }
  24.  
Sep 14 '07 #6
r035198x
13,262 8TB
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.
Sep 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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. ...
2
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. ...
0
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. ...
4
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. ...
1
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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
0
BarryA
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...
1
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...
0
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...
0
Oralloy
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.