Click to See Complete Forum and Search --> : Confussion about creation/copying,instantiaton.... which is happening?


Zirus Blackheart
March 30th, 2008, 01:19 PM
using System;

class Practice4_2
{
public static void Main(string[] args)
{
DateTime today;
today = DateTime.Now;

if (today.DayOfWeek == DayOfWeek.Sunday)
Console.WriteLine("Eat at Joe's");
}
}


Hi :-)

Conplete and utter n00b here :-)


Learning from a book and they don`t explan very well whats going on here.

It reads to me that DateTime today; is declaring an instance of the DateTime class, then today = DateTime.Now; is initiating it with the value "Now" so ya can do DateTime today = DateTime.Now;

The book tells me that everythings an object but it allso says that int and short ect are data types but then int.Parse(stringVariable); which converts the string numberr into an actual numeric number for maths ect
says is an object, a m8 says and it maked sence that theyre the same.

So, i`m just getting a little confused... am i instsantiating an instance of the DateTime class into an object and then assigning the object the value of "Now"?

Is DateTime today; declaring it and today = DateTime.Now; is initiating (giving it its initaal value) ?

Are the "simple data types" in c# objects? with metods ect?
where are theyre code on my hdd?

Thx alot for any help :) my brain will thank you massivly :-)

nelo
March 30th, 2008, 05:04 PM
C# is an object based language. Everything ultimately derives from System.Object. Having said that there are two main types in the .NET type system: reference types and value types. All the data types that you would have considered as literals in languages such as C++ are value types. These contain their own data directly and are allocated on the stack. Reference types are refer to their data indirectly and are allocated on the heap. To cut the story short classes are reference types, structs are value types. The 'int' keyword does not represent an integer primitive. Instead it maps to the .NET System.Int32 struct.

So, i`m just getting a little confused... am i instsantiating an instance of the DateTime class into an object and then assigning the object the value of "Now"?

Is DateTime today; declaring it and today = DateTime.Now; is initiating (giving it its initaal value) ?

That's right.

Are the "simple data types" in c# objects? with metods ect?

Yes. "simple" data types are value types that are ultimately derived from System.Object. So they all have a few basic methods. They also have specialised methods and properties (such as DateTime.Now) relevant to each type.

where are theyre code on my hdd?

You lost me here...

Anyway in a nutshell just take it easy. Don't be alarmed. Get familiar with the basic concept of the .NET Framework and with the syntax. You'll understand more as you go along.

Zirus Blackheart
March 31st, 2008, 08:43 AM
Ah ok great, so basicaly even int and sbyte ect are value type objects (in my head because they store a value) and if i have it right referance type are like a referance to an object, not sure on this because that makes me think of Pointers which point to something/anything stored in memory..... and referance objects is a referance to an object in memory?

Referance objects would be ya objects that actualy do something ya could say then? rather than just store a value (although valure types have some small methods like that conversion int.Parse) they serve a perpose such as Console opens a Console window then the Write method prints txt in said window Console.Write("blah");

Quote:
where are theyre code on my hdd?

You lost me here...

I was asking if they're source code is on my hdd so i can have a look at them.


Is there somewhere with a complete list of every method of every object in the .net framework? MSDN is confusing as hell.... in fact it suxx, ive looked at things on there i understand totaly from my book yet on that site itd written in such a way that it makes no sense at all heheh :-)

nelo
March 31st, 2008, 08:56 AM
You got the understanding right. References are just pointers to the location where the is stored on the heap. They don't carry the complexities of C++ pointers if you're familiar with those. I think is MSDN is quite good. Most of the time I can find what I'm looking for. I think the local MSDN library is better than the one on their website. That is the definitive source of information on the framework. There are book authors that have inside information on what goes on in the project teams in Microsoft and that have had access to the source code and are able to offer better insight. Other has tried to disassemble the .NET Framework libraries with a large degree of success. If I were you I would stick with MSDN for the moment.