To understand the c# language (and indeed the PLO, probably)?

Welcome.


There is a class (A) and nested inside a public class (In).


Why (?) we can declare an object instance of a nested class (In) here:


new A. B()


The class is not static also.

And why (?) we can't define it like so:


A A = new A();

new a.B();


The behaviour is as if the class is static, but it is not.


I can just deal with it, but I want to fully understand why this is so.


And one more question.

Why we need static classes? Inherit and create objects impossible.

This is an exotic alternative to namespaces? What can you do with them?


And yet another question:

Operation "as" equivalent to the type conversion through the brackets before the object?


Thank you.
October 8th 19 at 02:14
4 answers
October 8th 19 at 02:16
Solution
Why (?) we can declare an object instance of a nested class (In) here:

new A. B()

The class is not static also.
And why (?) we can't define it like so:

A A = new A();
new a.B();

when you instantiate the class using its full name, even if it is declared within another class.
static class is not being. class B contained in class A and has nothing to do with its instances.

>Why we need static classes? Inherit and create objects impossible.
This is an exotic alternative to namespaces? What can you do with them?

they are necessary when creating, for example, Extension Methods.
public static class MyExtensionProvider<br> {<br> public static void DoSomething(this Object targetObject)<br> {<br> return;<br> }<br> }<br>

about the as operator already answered.
Thank you. - Ramona_Bli commented on October 8th 19 at 02:19
October 8th 19 at 02:18
Afraid it all to OOP does not apply. Classes and static nested classes is a relic of other concepts, but not the PLO.
October 8th 19 at 02:20
Class B is the "property" of A class and not instances of this class. It's just the logic class is the essence of declarative, metadata, is used at compile time, not runtime. And the C# language static.
October 8th 19 at 02:22
Static classes need to combine global objects/functions. In particular, are often used to create utility classes (for Example, for some clever print a list of something).

Operation as not entirely equivalent to bring through the parenthesis.
If castes do not succeed — the variant with parentheses will generate an exception.
Whereas the variant with as — just return null
No, still the influence of Delphi to C#, well seen :) - Ramona_Bli commented on October 8th 19 at 02:25
Thank you. - Jared.Johns commented on October 8th 19 at 02:28

Find more questions by tags C