C# - instantiating an object

Started by
2 comments, last by SiCrane 12 years, 6 months ago
Hello,
I do not get one thing in C# and it seems total enigma to me. There are clasess in framework of .NET that contains only getter propreties and some methods which all do not alter inner data of the class. Example of such classes are many, for example System.Web.UI.Page class. But how can such object get instantieted and recieve data to itself?
An external function that gets a parameter or returns this object? But how the instructions in external function actualy do that if class is all private and has no functions to manipulate its data?
Advertisement
System.Web.UI.Page's members aren't mostly private, they are mostly protected. This is a class that's designed with some safe defaults who's behavior can be modified by inheritance. Each .aspx file creates a new class derived from Page possibly combined with additional code.

System.Web.UI.Page's members aren't mostly private, they are mostly protected. This is a class that's designed with some safe defaults who's behavior can be modified by inheritance. Each .aspx file creates a new class derived from Page possibly combined with additional code.


Thanks much. But inheritance is not always the case. For example sealed class HttpRequest. It has only Getters and 6 functions. It derives from object class right away. I do not see how possibly it can get data in , for example, its headers collection and so on. The constructor involves only few parameters from which this information can not be extracted.
System.Web.HttpRequest, in addition to the public constructor, has two internal constructors. One of these constructors accepts a HttpWorkerRequest object which contains information about the headers. You can find out this kind of information by using Reflector.

This topic is closed to new replies.

Advertisement