如果条件,如何在代码中调用函数

时间:2014-05-19 08:00:04

标签: c#

我想在if条件下调用代码中的函数。我在VB.net中有这个代码,但我无法将其转换为C#。这是VB代码:

 Dim SessionList As New List(Of Users)
 If SessionList.Where(Function(x) x.Title = My.Computer.Name).Count = 0 Then
            Dim TempUser As Users
            TempUser.Title = My.Computer.Name
            SessionList.Add(TempUser)
            Application("SessionList") = SessionList
        End If

我的脚本是:

 <script type="text/javascript">
    window.onload = function () {
        window.setInterval("Check_Message()", 3000);
    };

    function Check_Message(){
        var temp=httpGet("Default.aspx?Check=1");
        if (temp.length>0)
        {
            var TempMessage=$("#lblRecived").html();
            $("#lblRecived").html(TempMessage+temp);
        }
    }

    function httpGet(theUrl)
    {
        var xmlHttp = null;
        xmlHttp = new XMLHttpRequest();
        xmlHttp.open( "GET", theUrl, false );
        xmlHttp.send( null );
        return xmlHttp.responseText;
    }
</script>

2 个答案:

答案 0 :(得分:1)

这是C#版本:

List<Users> SessionList = new List<Users>();
if (SessionList.Where(x => x.Title == System.Environment.MachineName).Count() == 0) {
    Users TempUser = default(Users);
    TempUser.Title = My.Computer.Name;
    SessionList.Add(TempUser);
    Application("SessionList") = SessionList;
}

答案 1 :(得分:0)

试试这个:

if (SessionList.Where(x => x.Title == My.Computer.Name).Count = 0)        
{        
...       
}    

看看它是否有帮助。