我知道有很多线程在讨论这个问题,但到目前为止我还没有找到一个直接帮助我的情况.我需要从静态和非静态方法访问类的成员.但如果成员是非静态的,我似乎无法从静态方法中获取它们.
public class SomeCoolClass
{
public string Summary = "I'm telling you";
public void DoSomeMethod()
{
string myInterval = Summary + " this is what happened!";
}
public static void DoSomeOtherMethod()
{
string myInterval = Summary + " it didn't happen!";
}
}
public class MyMainClass
{
SomeCoolClass myCool = new SomeCoolClass();
myCool.DoSomeMethod();
SomeCoolClass.DoSomeOtherMethod();
}
Run Code Online (Sandbox Code Playgroud)
您如何建议我从任何一种方法获得摘要?
有没有办法查询对象列表,对它们进行分组,然后将它们作为列表列表输出为自己的列表?我不知道如何解释它,所以我会告诉你.
public class Note
{
string CreatorID;
string Title;
string Text;
}
Run Code Online (Sandbox Code Playgroud)
我有一个填充的笔记列表(List<Note> noteList).每个创作者都有多个创作者和多个笔记.我试图弄清楚是否有一种方法使用LINQ查询按照CreatorID对笔记进行分组,然后将它们分开并将它们作为笔记列表列表输出(List<List<Note>> creatorsNotes).通过这种方式,我可以循环创建者注释以获取创建者及其注释列表.