Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对.net core中其他文件夹中其他对象的引用_C#_Asp.net_.net_Model - Fatal编程技术网

C# 对.net core中其他文件夹中其他对象的引用

C# 对.net core中其他文件夹中其他对象的引用,c#,asp.net,.net,model,C#,Asp.net,.net,Model,我在.NETMVC中做过很多次,所以这应该很容易 我所需要做的就是引用一个方法,该方法位于我创建的用于清理代码的“Helper”文件夹中 我在Helpers文件夹中有这个方法 我可以将我的方法设置为静态,但它会给方法中的db部分带来相同的错误 引用该方法需要做什么?方法标识搜索不是静态的,因此不能这样调用它。 通过使用static关键字,可以使该方法成为静态的 private static SLGContext db = new SLGContext(); //Because IdentityS

我在.NETMVC中做过很多次,所以这应该很容易

我所需要做的就是引用一个方法,该方法位于我创建的用于清理代码的“Helper”文件夹中

我在Helpers文件夹中有这个方法

我可以将我的方法设置为静态,但它会给方法中的db部分带来相同的错误


引用该方法需要做什么?

方法标识搜索不是静态的,因此不能这样调用它。 通过使用static关键字,可以使该方法成为静态的

private static SLGContext db = new SLGContext(); //Because IdentitySearch is using that variable, so it has to be static.

public static List<int> IdentitySearch()
//Here the method body
private static SLGContext db=new SLGContext()//因为IdentitySearch正在使用该变量,所以它必须是静态的。
公共静态列表标识搜索()
//这里是方法体

这是否回答了您的问题?是的。谢谢尤金
        List<int> storeIdList = UserIdentity.IdentitySearch();
object reference required for non static field
private static SLGContext db = new SLGContext(); //Because IdentitySearch is using that variable, so it has to be static.

public static List<int> IdentitySearch()
//Here the method body