返回方法始终返回null [英] Return method always return null

查看:93
本文介绍了返回方法始终返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我的部分代码存在问题。 

Hello guys. I have a problem with a part of my code. 

此方法:

public ClinicHistory GetClinicHistoryByDate(DateTime date,person person)

        {

            //该人的Foreach诊所历史......

            foreach(ClinicHistory clinicHistory in person.ClinicHistory)

            {

                if(clinicHistory.Date == date)

                   返回诊所历史;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return null; < ---在此部分之前,if if返回对象

  &NBSP; &NBSP; &NBSP; }

public ClinicHistory GetClinicHistoryByDate(DateTime date, Person person)
        {
            // Foreach clinic history in the person...
            foreach (ClinicHistory clinicHistory in person.ClinicHistory)
            {
                if (clinicHistory.Date == date)
                    return clinicHistory;
            }
            return null; <--- Until this part, the if above returns the object
        }

我正在使用IoC,因为我在核心应用程序上有视图模型。

I'm using IoC because I have view models on a core application.

To得到我使用的对象: 

To get the object I use this: 

var clinicHistory = IoC.Patients.GetClinicHistoryByDate(DateTime.ParseExact(itemString," d / M / yyyy H:mm:ss",CultureInfo) .InvariantCulture),IoC.Patients.SelectedPatient);

var clinicHistory = IoC.Patients.GetClinicHistoryByDate(DateTime.ParseExact(itemString, "d/M/yyyy H:mm:ss", CultureInfo.InvariantCulture), IoC.Patients.SelectedPatient);

推荐答案

https:// www.dotnetperls.com/debugging

https://www.dotnetperls.com/debugging

我建议您使用调试器并开始查看变量内容,代码执行并找出自己的人,事和原因。 

I suggest that you use a debugger and start looking at variable content, code execution and find out the who, what and why yourself. 


这篇关于返回方法始终返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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