小编Nap*_*e95的帖子

在 C# 中遍历对象属性

我有一个客户类型对象列表,当我遍历该列表时,我希望能够遍历每个客户的属性。然后我想将该属性值打印为字符串。我收到 StackOverFlowException 错误。

让我先说:

  1. 这只是一个类库,我从其他地方调用该函数并且调用有效。
  2. 对数据库的调用及其返回的信息是正确的(我在尝试遍历属性之前对其进行了测试)
  3. 我的最终目标是将客户列表转换为二维数组,其中每列代表一个客户,每行代表客户属性。

提前致谢!

    using Dapper;
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.Xml.Linq;
    using System.Reflection.Emit;
    using System.Reflection;
    using System.Collections;

    namespace AtoCLib
    {
        public class DataAccessLayer
        {
            public static List<Customer> GetCustomerList(string startChar)
            {
                string sql = $"SELECT TOP (10) P.LastName, [CustomerID],[PersonID] ,[StoreID] ,[TerritoryID] ,[AccountNumber] FROM [AdventureWorks2017].[Sales].[Customer] C INNER JOIN [Person].[Person] P ON C.CustomerID = P.BusinessEntityID WHERE P.LastName >= '{startChar}'";
                List<Customer> CustomerList = new List<Customer>();

                try
                {
                    using (var connection = new SqlConnection("Data Source=SHCP-2035;Initial Catalog=AdventureWorks2017;Integrated Security=True"))
                    { …
Run Code Online (Sandbox Code Playgroud)

c# stack-overflow ienumerable ienumerator properties

0
推荐指数
2
解决办法
2万
查看次数