Want to build the ChatGPT based Apps? Start here
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Lui Wang
2.2k
5
728
How to pass vairable to class ?
Dec 17 2018 12:04 AM
I want run my code bellow,but it says that I can not use varialbe as type,how can I implement?
using
System;
using
System.Linq;
using
System.Reflection;
namespace
Mike.ConsoleApp
{
class
Program
{
static
void
Main(
string
[] args)
{
#region this is ok
Personal specifiedPersonal =
new
Personal();
Employee<Personal> employee =
new
Employee<Personal>();
employee.DoSth();
#endregion
#region this would be error
Assembly assmebly =
typeof
(Personal).GetTypeInfo().Assembly;
Type dynamicType = assmebly.ExportedTypes.Where(x => x.Name ==
"Personal"
).FirstOrDefault();
Employee<dynamicType> dynamicEmployee =
new
Employee<dynamicType>();
dynamicEmployee.DoSth();
#endregion
Console.ReadLine();
}
public
class
Personal
{
public
string
FirstName {
get
;
internal
set
; }
public
string
LastName {
get
;
internal
set
; }
}
public
class
Employee<TModel>
{
public
void
DoSth()
{
Console.WriteLine(
"Done !!!"
); ;
}
}
}
}
Reply
Answers (
2
)
When check in in tfs file it not included on project on sour
Api is not Working in Testing