小编Sri*_*m B的帖子

使用LINQ处理C#字典

如何使用LINQ Lambda Expression/Statemene Expression编写"//使用Foreach显示"循环实现?

我想简化我的开发并尽可能避免嵌套的foreach循环.我试图在第二个foreach语句中包含更多逻辑,我想使用Lambda/Statement表达式.

 internal class Program
{
    internal class Country
    {
        public string CountryName { get; set; }
        public int CountryCode { get; set; }
    }
    static void Main(string[] args)
    {
        List<Country> countries = new List<Country>()
        {
            new Country{CountryName = "India", CountryCode=1},
            new Country{CountryName = "Andaman Nicobar", CountryCode=1},
            new Country{CountryName = "United States of America",  CountryCode=2},
            new Country{CountryName = "Alaska",  CountryCode=2},
            new Country{CountryName = "Hawaii",  CountryCode=2},
            new Country{CountryName = "United Kingdom", CountryCode=3},
            new Country{CountryName = "Australia", CountryCode=4}
        }; …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

使用C#中的AE.Net.Mail访问GMail

我已经实现了以下示例代码来访问gmail并使用AE.Net.Mail获取前10个邮件主题.

我想知道到底出了什么问题,我一再得到错误

连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应173.194.79.108:993

这是代码.

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using AE.Net.Mail;
using AE.Net.Mail.Imap;
using System.Configuration;

namespace IMAP
{
    class Program
    {
        private static void Main()
        {
            var items = ReadMail();
            if (items != null && items.Count > 0)
            {
                foreach (var item in items.Take(10))
                {
                    Console.WriteLine(item.Subject);
                }
            }
            Console.ReadLine();
        }
        public static List<MailMessage> ReadMail()
        {
            List<MailMessage> messages = null;
            try
            {
                string userName = "yourname@gmail.com"; // Replace with your actual gmail id
                string passWord = "password"; // …
Run Code Online (Sandbox Code Playgroud)

c# gmail imap

5
推荐指数
1
解决办法
4768
查看次数

如何使用 C# 打破 List&lt;T&gt;.AsParallel().ForAll()

我正在使用 List.AsParallel().ForAll() PLINQ 实现。在循环内部,如果我发现某个条件成功,我希望循环立即脱离 ForAll() 循环。我怎样才能实现它?

这是示例代码。

using System;
using System.Collections.Generic;
using System.Linq;

namespace Basics
{
class Program
{
    class Family
    {
        public int SNo { get; set; }
        public string Name { get; set; }
    }

    static List<Family> families = null;
    static Program()
    {
        families = new List<Family>()
        {
            new Family(){SNo = 10, Name="Richard"},
            new Family(){SNo = 33, Name="Xio Fung"},
            new Family(){SNo = 10, Name="Sean"},
            new Family(){SNo = 10, Name="Andrea"},
            new Family(){SNo = 20, Name="Bjorn"},
            new Family(){SNo = 20, …
Run Code Online (Sandbox Code Playgroud)

plinq c#-4.0

5
推荐指数
1
解决办法
3646
查看次数

将List <T>作为查询字符串传递

我有一个列表,列表中有国家/地区名称.此列表需要作为Response.Redirect(页面)中的参数之一发送.

是否有直接的方法来执行此操作,以便在接收页面中,我可以将查询字符串类型转换为List并使用它.

谢谢,Sriram

asp.net

2
推荐指数
1
解决办法
8781
查看次数

标签 统计

c# ×2

asp.net ×1

c#-4.0 ×1

gmail ×1

imap ×1

linq ×1

plinq ×1