Newbie Questions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all, I am new to C# and have jst 2 questions for now..

1. I come from a VB6 background and I notice that declaring variables for certain objects in C# goes in the following format, for example : sqlDataAdapter da = new sqlDataadapter. My question is what is the purpose of the first statement? Why do I have to say sqlDataAdapter da = ........ why can't I just say da=........ What is the purpose of writing the first sqlDataAdapter, or any class name for that matter

2. Can someone please tell me what are/and what the differences are between a Basemanager Class and the CurrencyManager class - or could you point me in the right direction

Thanks for any hel
Kevin
 
Hi Kevin,
check out my response inline:

--
Branimir Giurov
MCSD.NET, MCDBA, MCT
eAgility LLC

Kevin said:
Hi all, I am new to C# and have jst 2 questions for now...

1. I come from a VB6 background and I notice that declaring variables for
certain objects in C# goes in the following format, for example :
sqlDataAdapter da = new sqlDataadapter. My question is what is the purpose
of the first statement? Why do I have to say sqlDataAdapter da = ........
why can't I just say da=........ What is the purpose of writing the first
sqlDataAdapter, or any class name for that matter?

You can look at this as a sort of inheritance of some of the language
features of C# from languages like C++ and Java - the truth is that in fact
the language designers tried to take all of the good "features" from every
single programming language on the market and build C# like their "dream
progamming language".

The other more simple explanation of this is that this way you can declare a
variable, without instantiating it - for example:

SqlDataAdapter da = null;

......

da = new SqlDataAdapter();

2. Can someone please tell me what are/and what the differences are
between a Basemanager Class and the CurrencyManager class - or could you
point me in the right direction?

I'm not sure what class you refer to (Basemanager ????), but in the .NET
Framework, the CurrencyManager is being used for collaborating with the
binding context of a form. Through the CurrencyManager you can get access to
the databindings of the form with the data in the back

For more info on the subject, check out
http://msdn.microsoft.com/library/d...stemWindowsFormsCurrencyManagerClassTopic.asp

Cheers,
Branimir
 
Kevin -

Just as in VB, C# requires that a declared variable be assigned to
something. For example, suppose in VB that you did the following:

Dim ds As System.Data.DataSet
Dim fpnames As DataTable

fpnames = ds.Tables.Add("Students")

If you tried to compile this you'd get the dreaded "Object reference
not set to an instance of an object" error. In other words, ds is
actually Nothing at this point. To assign it to something, you have
to make a New instance of it:

Dim ds As New System.Data.DataSet
Dim fpnames As DataTable

fpnames = ds.Tables.Add("Students")



Conversely, Dim fpnames As DataTable won't give you an error because
on the next line you're assigning it to one of the data sets tables.

So, in C#, the first part of the syntax is the declaration of the
variable and the second part of the syntax is its assignment:

DataSet ds = new DataSet();
DataTable fpnames ;

fpnames = ds.Tables.Add("Students");

In regards to your other question, go to this link and scroll down a
little. It has a good explanation about CurrencyManager, etc:

http://devcenter.infragistics.com/Articles/ArticleTemplate.Aspx?ArticleID=1266
 
Back
Top