Problem with reflection in C#

Joined
Jul 7, 2023
Messages
4
Reaction score
0
Hi guys,

I need help to solve the following:

First part of the task: Using reflection, it is necessary to examine the properties of the .NET class String. It is necessary to display the name of the class, its namespace, the name of the assembly in which it is located, the type it inherits, the interfaces it implements, as well as basic information about whether the class is abstract, sealed, generic, etc.

The second part of the task: The following class is given:

class Country
{
public string Name { get; set; }
public int Population { get; set; }


public Country(string name, int population)
{
Name = name;
Population = population;
}

public string GetCountryInfo()
{
return $"Country {Name} has the population of {Population}.";
}

}

Place the displayed class inside a new Visual Studio console project. Inside the program's Main method, use reflection to dynamically create an instance of the Country class, and then dynamically call the GetCountryInfo method. Display the obtained result inside the console.

I would be very thankful, if somebody can help.
 
Joined
Sep 4, 2022
Messages
128
Reaction score
16
Hello, here are some informations about 'reflection' with .Net, and C#



- About your Class :

setting "Name", and "Population" as 'public' menbers, you don't really need 'get' and 'set'.
By 'Public' keyword, the vars involved are reachable from all your project.
It's a fast access to your Object for sure
 
Joined
Jul 7, 2023
Messages
4
Reaction score
0
OK, thanks. I'm some kind of a beginner in this, so, time after time, I need help.
 
Joined
Sep 4, 2022
Messages
128
Reaction score
16
I got one good tips to add :

when you are in Visual Studio, in one of your project, you can join "microsoft online help and lessons".

  • select one keyword requiring more informations
  • press F1

it will bring you to a relevant online help page.
It's really useful !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top