如何将类名传递给C#中的方法 [英] How to pass class name to method in C#

查看:313
本文介绍了如何将类名传递给C#中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Sqlite for Windows 8.1 App在本地存储数据。我想创建SqliteHelper类作为泛型。我必须将类名作为参数传递给方法。那我该如何实现呢?

I am using Sqlite for Windows 8.1 App to store data locally. I want to create SqliteHelper class as generic. I have to pass class name as parameter to method. So how should I achieve this?

实际上必须使用Sqlite的CreateTableAsync方法创建表。它接受参数为Class。

Actually  have to create tables using CreateTableAsync method of Sqlite. It accepts parameter as Class.

私有异步任务CreateTable(strng tbleName)

Private async Task CreateTable(strng tbleName)

{

await conn .CreateTableAsync< tbleName>()

await conn.CreateTableAsync<tbleName>()

}

 它在这里给出错误。请帮助我。

 It gives error here. Please help me.

推荐答案

所以你已经创建了这个类,你需要在CreateTableAsync()方法中传递它的名称。您需要使用'Table'属性指定该特定类。

So have you created the class already, the name of which you need to pass in CreateTableAsync() method. You need to assign that particular class with 'Table' attribute.

[Table]
public class somename
{

}


这篇关于如何将类名传递给C#中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆