我需要检查邮件是否发送给现有收件人
这是我的代码
try
{
var smtpServer = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new System.Net.NetworkCredential(MAIL_FROM, PASSWORD),
EnableSsl = true
};
var mail = new MailMessage();
mail.From = MAIL_FROM
mail.To.Add(new MailAddress("nonexisting@gmail.com"));
mail.Subject = title;
mail.Body = content;
smtpServer.Send(mailMessage);
}
catch (SmtpFailedRecipientsException ex)
{
// never occures
}
Run Code Online (Sandbox Code Playgroud)
但是,当没有收件人时,SmtpFailedRecipientsException永远不会发生
有没有办法配置SmtpServer来触发此异常?
我是C#和xaml代码的新手.我有一个用C#实现的示例代码.当我查看了xaml文件时,我得到了<Window x:Class="test.MainWindow">
.
所以确实test.MainWindow
指出了这个窗口的类名.
我试图从win 32中开发的其他应用程序调用此窗口.我试图将此类名称传递给FindWindow("test.MainWindow",NULL)
,但它失败了.在那边做了什么遗失.
如何更改C#中开发的窗口的类名?
谢谢,
萨加尔
我的C#应用程序上有一些webBrowsers,实际上我有10. webBrowser0,webBrowser1,webBrowser2等等.
无论如何,我正在执行一个循环来计算每个屏幕以在我拥有的每个屏幕上放置webBrowser,这一切都很容易完成,但在我的循环中,如果有这样的东西.
for (index = 0; index <= totalScreens; index++)
{
if (index == 0)
{
webBrowser0.Width = x;
webBrowser0.Height = x;
}
if (index == 1)
{
webBrowser1.Width = x;
webBrowser1.Height = x;
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我在代码上加倍了,所以如果我可以引用webBrowser {index}那将是完美的但当然不起作用.
我在Visual Studio 2008中工作.
我有一个格式为"hh:mm:ss"的字符串输入,我想以相同的格式转换为dateTime.
我使用了Convert.ToDateTime()函数来转换它,但也为它添加了一个日期.有没有办法在不添加日期的情况下转换它?
scanStartString = "08:00:00"
scanStart = Convert.ToDateTime(scanStartString)
'scanStart = "16/05/2011 08:00:00"
'required "08:00:00"
Run Code Online (Sandbox Code Playgroud)
干杯,帽子
我想用来MySqlParameter
将tableName传递给查询(以防止slq注入)
MySqlCommand cmd = new MySqlCommand("select * from @table"), cn)
cmd.Parameters.AddWithValue("@table",TableName);
Run Code Online (Sandbox Code Playgroud)
但这不起作用.如何将tableName作为参数传递
PS我试图改变@
到?
-不工作
当此代码运行显示我此错误:"对象引用未设置为对象的实例"错误发生在第一行=> MinorDBDataContext mdc = new
...
而且对于"for(int i; i <1005; i ++){}"的序列也可以正常工作.
有什么问题 ?
Thread.CurrentThread.Priority = ThreadPriority.Highest;
var query = from M in new MajorDBDataContext().User_Accounts select M;
List<User_Account> Ulist = query.ToList();
string d = DateTime.Now.ToString();
int c = 0;
string temp ="";
Parallel.For(0, 1005, (i,loop) =>
{
try
{
MinorDBDataContext mdc = new MinorDBDataContext(_Filings.OnServerRepository(Ulist[i].user_Sys_DBPath));
GoodJob(mdc, temp, i);
DA.Page page = mdc.Pages.Single();
temp += mdc.Minor_Users.Take(1).SingleOrDefault().Minor_User_Email;
temp += mdc.Minor_Users.Take(1).SingleOrDefault().Minor_User_Name;
temp += mdc.Minor_Users.Take(1).SingleOrDefault().Minor_User_Family + i.ToString();
}
catch { }
});
append(temp);
Run Code Online (Sandbox Code Playgroud) 我有这样的util类:
public class Util
{
static public List<Person> PersonList{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我想在Main方法中将Item添加到我的列表中,如下所示:
void Main()
{
Util.PersonList.Add(new Person{ Name="A" });
}
Run Code Online (Sandbox Code Playgroud)
但它不可能...... PersonList为空?
我从用户那里得到一个字符串,然后把它放在一个char数组中.现在我想显示字符串中的所有字符以及它们出现的次数.我的代码如下请纠正我?
using System;
class count
{
public void charcount()
{
int i ;
int count = 0;
string s;
Console.WriteLine("Enter the String:");
s = Console.ReadLine();
char[] carr = s.ToCharArray();
for(i = 0; i < carr.Length; i++)
{
for(int j = 1; j < carr.Length; j++)
{
if(carr[j] == carr[i])
{
count++;
}
else
{
return;
}
Console.WriteLine("The Character " + carr[i] + " appears " + count);
}
}
}
static void Main()
{
count obj = new count();
obj.charcount(); …
Run Code Online (Sandbox Code Playgroud) 您好我想用一些函数创建一个dll.对于初学者,我试图做一些简单的例子来测试.我正在创建一个新的类库,例如下面的代码.当我构建它(没有错误)并创建一个dll文件时,我尝试在我的其他项目中使用它
[DllImport("nllibrary.dll")]
public static extern long Add(long i, long j);
Run Code Online (Sandbox Code Playgroud)
我可以编译它,但当我尝试运行应用程序时,它给我错误"找不到入口点".当我用depends.exe查看这个dll时,它在dll中没有显示任何功能.我的dll有什么问题?
dll的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace nlLibrary
{
public class nlClass
{
public static long Add(long i, long j)
{
return (i + j*2);
}
}
}
Run Code Online (Sandbox Code Playgroud) 是否有一种高性能的方法可以将非常大的CSV文件(大小为几千兆字节)加载到带有.NET的SQL-Server 2008数据库中?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
namespace GUISimpleTCPClient
{
public partial class GUISimpleTCPClient : Form
{
TcpClient client=null;
NetworkStream stream;
StreamReader reader;
StreamWriter writer;
public GUISimpleTCPClient()
{
InitializeComponent();
}
private void Connect_Click(object sender, EventArgs e)
{
try
{
client=new TcpClient(ipAddress.Text,Convert.ToInt32(port.Text));
listBox1.Items.Add("Connected to Server");
stream = client.GetStream();
reader = new StreamReader(stream);
writer = new StreamWriter(stream);
string msg = reader.ReadLine();
listBox1.Items.Add("Recieved form …
Run Code Online (Sandbox Code Playgroud)