ninanina12
Početnik
- Poruka
- 3
Molim pomoc oko sledeceg zadatka, stalno mi izbacuje gresku
Zadatak glasi:
Data je sledeća klasa:
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}.";
}
}
Unutar Main metode programa, korišćenjem refleksije obavite dinamičko kreiranje instance klase Country, a zatim i dinamičko pozivanje metode GetCountryInfo. Dobijeni rezultat prikažite unutar konzole.
ovako sam ja uradila tj. pokusala;-))
using System.Reflection;
using System.Text;
namespace System { }
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}.";
}
}
public class Program
{
static void Main(string[] args)
{
Assembly assembly = null;
try
{
assembly = Assembly.Load("Country");
}
catch (FileNotFoundException exc)
{
Console.WriteLine(exc.Message);
}
return;
Type country = assembly.GetType("Country");
object obj = Activator.CreateInstance(country);
MethodInfo methodInfo = country.GetMethod("GetCountryInfo");
object[] parameters = new object[] { };
methodInfo.Invoke(obj, parameters);
Console.ReadLine();
}
private static object CreateInstance(Type? country)
{
throw new NotImplementedException();
}
}
Hvala unapred na pomoci!
Nina
Zadatak glasi:
Data je sledeća klasa:
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}.";
}
}
Unutar Main metode programa, korišćenjem refleksije obavite dinamičko kreiranje instance klase Country, a zatim i dinamičko pozivanje metode GetCountryInfo. Dobijeni rezultat prikažite unutar konzole.
ovako sam ja uradila tj. pokusala;-))
using System.Reflection;
using System.Text;
namespace System { }
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}.";
}
}
public class Program
{
static void Main(string[] args)
{
Assembly assembly = null;
try
{
assembly = Assembly.Load("Country");
}
catch (FileNotFoundException exc)
{
Console.WriteLine(exc.Message);
}
return;
Type country = assembly.GetType("Country");
object obj = Activator.CreateInstance(country);
MethodInfo methodInfo = country.GetMethod("GetCountryInfo");
object[] parameters = new object[] { };
methodInfo.Invoke(obj, parameters);
Console.ReadLine();
}
private static object CreateInstance(Type? country)
{
throw new NotImplementedException();
}
}
Hvala unapred na pomoci!
Nina