首页 文章 精选 留言 我的

精选列表

搜索[c 语言],共10000篇文章
优秀的个人博客,低调大师

c# 利用IMap 收取163邮件

最近我要做一个爬虫。这个爬虫需要如下几个步骤: 1 填写注册内容(需要邮箱注册) 2 过拖拽验证码(geetest) 3 注册成功会给邮箱发一封确认邮箱 4 点击确认邮箱中的链接 完成注册 我这里就采用163邮箱注册。 邮箱协议有 pop3 和 imap 和 smtp 我试了pop3 不能够筛选邮件 例如筛选未读 和 发件人这2个条件 所以放弃用pop3 imap协议是支持的。 我就找了一个开源的第三方lib:S22.Imap 用法很简单: public void Test163() { var imapServer = "imap.163.com"; var port = 993; using (ImapClient client = new ImapClient(imapServer, port, "xxxx@163.com", "pwd", AuthMethod.Login, true)) { // Returns a collection of identifiers of all mails matching the specified search criteria. IEnumerable<uint> uids = client.Search(SearchCondition.Unseen()); // Download mail messages from the default mailbox. IEnumerable<MailMessage> messages = client.GetMessages(uids,FetchOptions.HtmlOnly); Console.WriteLine("We are connected!"); } } 发现 在login的时候 报错了: 提示“NO Select Unsafe Login. Please contact kefu@188.com for help”。 163邮箱也会收到一个告警邮件 经过查证 发现得需要在发送 login 命令之前 得先发送 id 命令 至于为什么要这么做 我的理解是得先伪装成普通的客户端吧(有理解错误请指出谢谢) 我fork了一份SS2.imap的代码 打算兼容163的这个特殊情况改掉源码 然后走Login方法就不会报错了 Github地址:https://github.com/yuzd/S22.Imap 如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,转载文章之后须在文章页面明显位置给出作者和原文连接,谢谢。

优秀的个人博客,低调大师

C#中结构struct的使用

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace Demo{ enum orientation:byte { 北 = 1, 南 = 2, 东 = 3, 西 = 4 } struct route { public orientation direction; public double distance; } class Program { static void Main(string[] args) { route myRoute; int myDirection = -1; double myDistance; Console.WriteLine("1)北\n 2)南\n 3)东\n 4)西\n"); do { Console.WriteLine("选择一个方向:"); myDirection = Convert.ToInt16(Console.ReadLine()); } while (myDirection < 1 || myDirection > 4); Console.WriteLine("输入一个距离:"); myDistance = Convert.ToDouble(Console.ReadLine()); myRoute.direction = (orientation)myDirection; myRoute.distance = myDistance; Console.WriteLine("方向是{0},距离是{1}!",myRoute.direction,myRoute.distance); Console.ReadKey(); } } }结构比枚举更复杂,可以保存多种类型的数据! 本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6728565.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

C#运算符小例子

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace Demo{ class Program { static void Main(string[] args) { Console.WriteLine("输入一个数字:"); int myInt = Convert.ToInt32(Console.ReadLine()); bool isLessThan10 = myInt < 10; bool isBetween0And5 = (0 <= myInt) && (myInt <= 5); Console.WriteLine("数字小于10? {0}",isLessThan10); Console.WriteLine("数字在0和5之间? {0}", isBetween0And5); Console.ReadKey(); } } } 本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6707627.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

C#中访问私有成员

首先我必须承认访问一个类的私有成员不是什么好做法。大家也都知道私有成员在外部是不能被访问的。而一个类中会存在很多私有成员:如私有字段、私有属性、私有方法。对于私有成员访问,可以套用下面这种非常好的方式去解决。 private string name; public string Name { get { return name; } set { name = value; } } 但是有时候,源代码是别人的,你就不能修改源代码,只提供给你dll。或者你去维护别人的代码,源代码却有丢失。这样的情况如果你想知道私有成员的值,甚至去想直接调用类里面的私有方法。那怎么办呢?其实在.net中访问私有成员不是很难,这篇文章提供几个简单的方法让你如愿以偿。 为了让代码用起来优雅,使用扩展方法去实现。 1、得到私有字段的值: public static T GetPrivateField<T>(this object instance, string fieldname) { BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic; Type type = instance.GetType(); FieldInfo field = type.GetField(fieldname, flag); return (T)field.GetValue(instance); } 2、得到私有属性的值: public static T GetPrivateProperty<T>(this object instance, string propertyname) { BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic; Type type = instance.GetType(); PropertyInfo field = type.GetProperty(propertyname, flag); return (T)field.GetValue(instance, null); } 3、设置私有成员的值: public static voidSetPrivateField(this objectinstance,stringfieldname,objectvalue) { BindingFlagsflag =BindingFlags.Instance |BindingFlags.NonPublic; Typetype = instance.GetType(); FieldInfofield = type.GetField(fieldname, flag); field.SetValue(instance, value); }4、设置私有属性的值:public static voidSetPrivateProperty(this objectinstance,stringpropertyname,objectvalue) { BindingFlagsflag =BindingFlags.Instance |BindingFlags.NonPublic; Typetype = instance.GetType(); PropertyInfofield = type.GetProperty(propertyname, flag); field.SetValue(instance, value,null); }5、调用私有方法: public staticT CallPrivateMethod<T>(this objectinstance,stringname,params object[] param) { BindingFlagsflag =BindingFlags.Instance |BindingFlags.NonPublic; Typetype = instance.GetType(); MethodInfomethod = type.GetMethod(name, flag); return(T)method.Invoke(instance, param); } 测试: 下面我们使用一个测试类,进行测试。新建一个类库项目,测试的类代码如下: public class TestClass { public TestClass() { privatefield1 = 1; privatefield2 = 99; PrivateFieldA = "Lo"; PrivateFieldB = "ve"; } private int privatefield1; private int privatefield2; private string PrivateFieldA { get; set; } private string PrivateFieldB { get; set; } private int Add() { return privatefield1 + privatefield2; } private string Join() { return PrivateFieldA + PrivateFieldB; } } 将上面类库的dll引入控制台项目中。使用下面代码去使用这个类的私有成员: TestClass obj = new TestClass(); System.Console.WriteLine("私有字段"); System.Console.WriteLine(obj.GetPrivateField<int>("privatefield1")); System.Console.WriteLine(obj.GetPrivateField<int>("privatefield2")); System.Console.WriteLine("私有属性"); System.Console.WriteLine(obj.GetPrivateProperty<string>("PrivateFieldA")); System.Console.WriteLine(obj.GetPrivateProperty<string>("PrivateFieldB")); System.Console.WriteLine("私有方法"); System.Console.WriteLine(obj.CallPrivateMethod<int>("Add",null)); System.Console.WriteLine(obj.CallPrivateMethod<string>("Join", null)); System.Console.WriteLine("修改私有属性"); obj.SetPrivateProperty("PrivateFieldA", "hello"); obj.SetPrivateProperty("PrivateFieldB", "world"); System.Console.WriteLine(obj.CallPrivateMethod<string>("Join", null)); System.Console.Read(); 结果如下: 总结:实现对类私有成员的访问。 本文转自麒麟博客园博客,原文链接:http://www.cnblogs.com/zhuqil/archive/2010/07/25/Access-Private-Member.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

C++学习第三天

一些基础就可以略过了,看书不能太呆板。 如果把一本书看完了,剩下的就是在实际项目中进行整合,训练,然后整理成笔记。 每天敲点程序,记点笔记。 变量作用域 代码: #include <iostream> #include <string> #include <conio.h> std::string s1 = "hello"; //全局 int main(){ std::string s2 = "world"; //局部 std::cout<<s1<<" "<<s2<<std::endl; int s1 = 42; //局部+隐式全局 std::cout<<s1<<" "<<s2<<std::endl; getch(); return 0; } 结果:hello world42 world判断代码输出结果 代码: #include <iostream> #include <string> #include <conio.h> int i = 42; int main(){ int i = 100,sum = 0; for(int i = 0;i!=10;++i) sum += i; std::cout<<i<<" "<<sum<<std::endl; getch(); return 0; } 结果:100 45 用class和struct关键字定义类的唯一差别在于默认访问级别:默认情况下,struct的成员为public,而class的成员为private。一旦使用了using声明,我们就可以直接引用名字,而不需要再引用改名字的命名空间了。 代码: #include <iostream> #include <string> #include <conio.h> using std::cin; using std::string; using std::cout; int main(){ string s; cin>>s; cout<<s; getch(); return 0; } #include <iostream> #include <string> #include <conio.h> using std::cin; using std::string; using std::cout; using std::endl; int main(){ string st("The expense of spirit\n"); cout<<"The size of "<<st<<"is"<<st.size() <<" characters,including the newline"<<endl; getch(); return 0; } 结果:The size of The expense of spiritis22 characters,including the newline 本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/archive/2013/04/11/3014962.html,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码