如何用C#解决语法问题?
好的,我一直在回避一些语法问题( 一个是在类型或名称空间定义的末尾,或者是预期的文件结尾 另一个是在如何用C#解决语法问题?,c#,syntax,C#,Syntax,好的,我一直在回避一些语法问题( 一个是在类型或名称空间定义的末尾,或者是预期的文件结尾 另一个是在private static void OnTimedEvent1(对象源,ElapsedEventArgs e)的一半处,带有{expected} 谢谢 实际代码:(我也把错误放在这里) 在另一个方法中有一个方法 private static void OnTimedEvent1(object source, ElapsedEventArgs e) { // { expecte
private static void OnTimedEvent1(对象源,ElapsedEventArgs e)
的一半处,带有{expected}
谢谢
实际代码:(我也把错误放在这里)
在另一个方法中有一个方法
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)
这可能就是您正在尝试执行的操作--您希望从事件处理程序中调用CheckMail()
using System;
using System.Net;
using System.Timers;
using System.Xml;
namespace Gmail_final_prep
{
public class Gmail_FP
{
private static System.Timers.Timer gTimer;
public static void GMain()
{
gTimer = new System.Timers.Timer(2000);
// Hook up the Elapsed event for the timer.
gTimer.Elapsed += OnTimedEvent1;
gTimer.Interval = 2000;
gTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();
// If the timer is declared in a long-running method, use
// KeepAlive to prevent garbage collection from occurring
// before the method ends.
//GC.KeepAlive(gTimer);
}
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
CheckMail();
}
public static string TextToBase64(string sAscii)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bytes = encoding.GetBytes(sAscii);
return System.Convert.ToBase64String(bytes, 0, bytes.Length);
}
public static string CheckMail()
{
string result = "0";
try
{
var url = @"https://gmail.google.com/gmail/feed/atom";
var USER = "usr";
var PASS = "pss";
var encoded = TextToBase64(USER + ":" + PASS);
var myWebRequest = HttpWebRequest.Create(url);
myWebRequest.Method = "POST";
myWebRequest.ContentLength = 0;
myWebRequest.Headers.Add("Authorization", "Basic " + encoded);
var response = myWebRequest.GetResponse();
var stream = response.GetResponseStream();
XmlReader reader = XmlReader.Create(stream);
System.Text.StringBuilder gml = new System.Text.StringBuilder();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
if (reader.Name == "fullcount")
{
gml.Append(reader.ReadElementContentAsString()).Append(",");
//result = reader.ReadElementContentAsString();
//return result;
}
}
Console.WriteLine(gml.ToString());
}
catch (Exception ee) { Console.WriteLine(ee.Message); }
return result;
}
}
} // Type or namespace definition, or end-of-file expected here
这是不合法的——您不能将一种方法嵌入另一种方法。我想知道这部分在做什么:
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)
你的问题可能就在这里。哇,谢谢!我不知道我怎么会错过这个(改为在eventhandler中调用它),但是我又一次错过了一个方法中的方法…非常感谢!
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)
{
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)