Hi everybody, I am required to find out if the following is a standard practice to create a subclass.
Take for instance, I have to create a class library (ClLib) with 2 classes using Visual Studio: Class1.cs & Class2.cs.
Next, I open up the .CSPROJ file of ClLib and modify the following line:
<Compile Include="Class2.cs" />
to become
<Compile Include="Class2.cs" >
<DependentUpon> Class1.cs </DependentUpon>
Can any kind soul help me solve this question? Your help would be greatly appreciated!

1 answers
The standard practice to create a subclass using C# code is:
In other words, you specify the parent class after a colon in the subclass's definition.
If you don't specify a parent class, then the class is considered to derive directly from System.Object.
The snippet you have shown from the project file is simply an instruction to MSBuild (used by Visual Studio in the background) regarding the building of the project.
The 'DependentUpon' tag is used to specify a dependency between two files. For example, in a WPF application, you might have a 'code behind' file MyProg.xaml.cs which is dependent upon the corresponding xaml file MyProg.xaml. In such cases, the two files will build to a single class, albeit split into two partial classes.
answered 2 years ago by:
17279
12
Okay, then how do I make it show in Solution Explorer (Visual Studio) that Class 2 is indented below Class 1? So you mean that even for creating subclasses in Class Library, the standard practice is to specify the parent class after a colon in the subclass's definition. The modification in the .CSPROJ file is not a standard practice, yeah?
17279
Using the DependentUpon tag in the project file, WILL cause Class2 to be indented under Class1 in Solution Explorer. However, this just indicates that there is a dependency between the files (such as the 'code behind' dependency on an HTML/XAML file in ASP.NET/WPF applications). It doesn't mean that one class is a subclass (i.e. a derived class) of another and for that you MUST specify the parent class after a colon in the subclass's definition. A C# application doesn't in fact need a project file at all - it's just a convenience which makes building complex applications easier and also makes it easier for tools to display associations between files.