473,471 Members | 4,616 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Static method question

Hi, everyone.

I have a C# class like following .

public class CommGlaVariantIO : BCCBase
{

private DataSet _dataSetTblSchema = new DataSet();

public void InitAllSchema()
{
DirectoryInfo directoryInfo;

directoryInfo = new DirectoryInfo(WebConfiguration.GetSchemaFilePath);

foreach(FileInfo fileInfo in directoryInfo.GetFiles("*Schema.xsd"))
{
DataSet dsSchema = TblSchemaLib.GetTblSchema(fileInfo.FullName, true);
_dataSetTblSchema.Tables.Add(dsSchema.Tables[0].Copy());
}
}
}

I want at another class to get the _dataSetTblSchema value,who can tell me how to resolve this .

thanks!
jiangyh
Nov 16 '05 #1
8 1112
jiangyh <ca****@msn.com> wrote:
Hi, everyone.

I have a C# class like following .

public class CommGlaVariantIO : BCCBase
{

private DataSet _dataSetTblSchema = new DataSet();

public void InitAllSchema()
{
DirectoryInfo directoryInfo;

directoryInfo = new DirectoryInfo(WebConfiguration.GetSchemaFilePath);

foreach(FileInfo fileInfo in directoryInfo.GetFiles("*Schema.xsd"))
{
DataSet dsSchema = TblSchemaLib.GetTblSchema(fileInfo.FullName, true);
_dataSetTblSchema.Tables.Add(dsSchema.Tables[0].Copy());
}
}
}

I want at another class to get the _dataSetTblSchema value,who can
tell me how to resolve this .


You need to either make _dataSetTblSchema public (which is nasty) or
expose it through a public property or method call. (Internal would
work in both cases too, assuming the other class is in the same
assembly.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
hi Jon Skeet [C# MVP]:

thanks you help.but I want get the _dataSetTblSchema value from another
project that they aren't in the same assembly.can u give me some souce to
resolve this.

"Jon Skeet [C# MVP]" <sk***@pobox.com> ????
news:MP************************@msnews.microsoft.c om...
jiangyh <ca****@msn.com> wrote:
Hi, everyone.

I have a C# class like following .

public class CommGlaVariantIO : BCCBase
{

private DataSet _dataSetTblSchema = new DataSet();

public void InitAllSchema()
{
DirectoryInfo directoryInfo;

directoryInfo = new DirectoryInfo(WebConfiguration.GetSchemaFilePath);
foreach(FileInfo fileInfo in directoryInfo.GetFiles("*Schema.xsd"))
{
DataSet dsSchema = TblSchemaLib.GetTblSchema(fileInfo.FullName, true); _dataSetTblSchema.Tables.Add(dsSchema.Tables[0].Copy());
}
}
}

I want at another class to get the _dataSetTblSchema value,who can
tell me how to resolve this .


You need to either make _dataSetTblSchema public (which is nasty) or
expose it through a public property or method call. (Internal would
work in both cases too, assuming the other class is in the same
assembly.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
jiangyh <ca****@msn.com> wrote:
thanks you help.but I want get the _dataSetTblSchema value from another
project that they aren't in the same assembly.can u give me some souce to
resolve this.


As I said, add a public property or method. If you can't change the
class, you're stuck - you're not *meant* to be able to get at private
variables.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

hi Jon Skeet :

I add a property and set the variant _dataSetTblSchema to public.But I want get the variant value without instance the class,when I instance the CommGlaVariantIO class, the variant _dataSetTblSchema value will lose.

public DataSet GetTblSchema
{
get{return _dataSetTblSchema;}
set{_dataSetTblSchema = value;}
}

public DataSet _dataSetTblSchema = new DataSet();

"Jon Skeet [C# MVP]" <sk***@pobox.com> 写入邮件 news:MP************************@msnews.microsoft.c om...
jiangyh <ca****@msn.com> wrote:
thanks you help.but I want get the _dataSetTblSchema value from another
project that they aren't in the same assembly.can u give me some souce to
resolve this.


As I said, add a public property or method. If you can't change the
class, you're stuck - you're not *meant* to be able to get at private
variables.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
Jon Skeet [C# MVP] wrote:
jiangyh <ca****@msn.com> wrote:
thanks you help.but I want get the _dataSetTblSchema value from another
project that they aren't in the same assembly.can u give me some souce to
resolve this.

As I said, add a public property or method. If you can't change the
class, you're stuck - you're not *meant* to be able to get at private
variables.


Except through reflection :)
But we wont go there.

JB
Nov 16 '05 #6
How about passing a reference of the object you want deal with to
InitAllSchema?

Etienne Boucher
Nov 16 '05 #7
jiangyh <ca****@msn.com> wrote:
I add a property and set the variant _dataSetTblSchema to public.But
I want get the variant value without instance the class,when I
instance the CommGlaVariantIO class, the variant _dataSetTblSchema
value will lose.


If you don't have an instance there *isnt'* any value for
_dataSetTblSchema.

Either you should make sure you use the same instance at all the
appropriate places, or make the field and the method/property static.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
thanks Jon Skeet:

I know ,my source must like following

public static string a;
public static string GetA()
{
return a;
}

"Jon Skeet [C# MVP]" <sk***@pobox.com> 写入邮件 news:MP************************@msnews.microsoft.c om...
jiangyh <ca****@msn.com> wrote:
I add a property and set the variant _dataSetTblSchema to public.But
I want get the variant value without instance the class,when I
instance the CommGlaVariantIO class, the variant _dataSetTblSchema
value will lose.


If you don't have an instance there *isnt'* any value for
_dataSetTblSchema.

Either you should make sure you use the same instance at all the
appropriate places, or make the field and the method/property static.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Murat Tasan | last post by:
so here is another general question about java... why can't you declare an abstract static method. i can envision the case (indeed i have experienced the case) where one would want an...
1
by: baylor | last post by:
In C#, an interface cannot mark any method as static. i'm told the ILASM supports it but i've never tested that Two questions. First, why? OK, i've heard the reason about interfaces being...
10
by: Marek | last post by:
Hi, I am analyzing Duwamish7 source code boundled with Visual Studio .NET 2003. Could anoybody explain why the Monitor.Enter and Monitor.Exit block is used inside a static constructor? The code...
9
by: Clint | last post by:
Hey all - Excuse the cross-post ... I'm not sure what the appropriate newsgroup would be for this question. I have a question that I'm not quite sure how to ask. For all I know, I have the...
15
by: dn | last post by:
I'm starting an n-tier application with an ASP.NET 2.0 presentation layer, a business layer, a data access layer, and a SQL Server 2005 database, and I have a question. In the business and data...
12
by: chandu | last post by:
hello, i want to know usage of static methods in a class. is it advantageous or disadvantage to use more static methods in a class. thank u
10
by: Franky | last post by:
I think I misread a post and understood that if I do: System.Windows.Forms.Cursor.Current = Cursors.WaitCursor there is no need to reset the cursor to Default. So I made all the reset...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
37
by: minkoo.seo | last post by:
Hi. I've got a question on the differences and how to define static and class variables. AFAIK, class methods are the ones which receives the class itself as an argument, while static methods...
0
by: Joe Strout | last post by:
Hi Luis, A static variable IS encapsulation. Encapsulation happens at many levels: module, class, instance, and (in languages that support it) method. A static local variable is simply the...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.