小编Zbo*_*one的帖子

C#引用另一个方法的变量

我是C#的新手,我真的需要知道如何从另一个方法调用/使用字符串.

例如:

public void button1_Click(object sender, EventArgs e)
{ 
    string a = "help";
}

public void button2_Click(object sender, EventArgs e)
{
    //this is where I need to call the string "a" value from button1_click 
    string b = "I need ";
    string c = b + a;          
}
Run Code Online (Sandbox Code Playgroud)

所以在这个例子中我需要调用函数中函数中定义的字符串" a "button1_Click()button2_Click()

谢谢!!

c# methods call

9
推荐指数
3
解决办法
10万
查看次数

CSS:使容器适合屏幕

我正在开发一个有两个容器的网站:侧边栏和主要内容。问题是,当最小化窗口(仅)时,左侧边栏适合屏幕当前大小的大小,向下滚动时,侧边栏消失。这仅在内容容器(右侧)未填充时发生屏幕..

您可以尝试最小化此页面,当窗口最小化时,向下滚动时,您会看到左侧栏消失。

您可以尝试一个包含更多内容的好页面,您会看到这里一切正常..

我试过 height="100%" and width="100%"

html css overflow

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

Matchcollection Parallel.Foreach

我正在尝试为matchcollection创建一个Parallel.Foreach循环.这是我建造的刮刀.我只需要知道在Parallel.Foreach中放什么

MatchCollection m = Regex.Matches(htmlcon, matchlink, RegexOptions.Singleline);

                Parallel.ForEach(WHAT DO I PUT HERE? =>
                {

                        Get(match.Groups[1].Value, false);
                        Match fname = Regex.Match(htmlcon, @"<span class=""given-name"(.*?)</span>", RegexOptions.Singleline);
                        Match lname = Regex.Match(htmlcon, @"span class=""family-name"">(.*?)</span>", RegexOptions.Singleline);

                        firstname = fname.Groups[1].Value;
                        lastname = lname.Groups[1].Value;

                        sw.WriteLine(firstname + "," + lastname);
                        sw.Flush();

                }):
Run Code Online (Sandbox Code Playgroud)

我试过了:

Parallel.ForEach<MatchCollection>(m,match  =>
Run Code Online (Sandbox Code Playgroud)

但没有运气!

提前致谢!:)

c# parallel-processing multithreading

4
推荐指数
1
解决办法
1420
查看次数

Streamreader问题

我是C#的一个真正的小伙子试图根据我的一个朋友在他的一个应用程序中使用的短代码编写一个小的XML替代程序.

我遇到这条线路有问题:

StreamReader sr = new StreamReader(textBox1.Text);
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:"空路径名称不合法." 为什么这不起作用?

代码是:

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;

namespace ReplaceMe
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        StreamReader sr = new StreamReader(textBox1.Text);
        StreamWriter sw = new StreamWriter(textBox1.Text.Replace(".", "_new."));
        string cur = "";
        do
        {
            cur = sr.ReadLine();
            cur = cur.Replace(textBox2.Text, textBox3.Text);
            sw.WriteLine(cur);
        }
        while (!sr.EndOfStream);

        sw.Close();
        sr.Close();

        MessageBox.Show("Finished, the new file is in the same …
Run Code Online (Sandbox Code Playgroud)

.net c#

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

C#Parallel ForEach保持值

我正在开发一款可在Google搜索结果网址中搜索电子邮件地址的应用.问题是它需要将每个页面中找到的值+它找到电子邮件的URL返回到包含2列的数据网格视图:电子邮件和URL.我正在使用Parallel.ForEach这个,但它当然返回随机URL,而不是它真正找到的电子邮件.

public static string htmlcon;  //htmlsource

public static List<string> emailList = new List<string>();

public static string Get(string url, bool proxy)
    {
        htmlcon = "";

        try
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            if (proxy)
                req.Proxy = new WebProxy(proxyIP + ":" + proxyPort);
            req.Method = "GET";
            req.UserAgent = Settings1.Default.UserAgent;
            if (Settings1.Default.EnableCookies == true)
            {
                CookieContainer cont = new CookieContainer();
                req.CookieContainer = cont;
            }
            WebResponse resp = req.GetResponse();
            StreamReader SR = new StreamReader(resp.GetResponseStream());
            htmlcon = SR.ReadToEnd();

            Thread.Sleep(400);
            resp.Close();
            SR.Close();
        }
        catch (Exception)
        {
            Thread.Sleep(500); …
Run Code Online (Sandbox Code Playgroud)

c# parallel-processing foreach plinq

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

标签 统计

c# ×4

parallel-processing ×2

.net ×1

call ×1

css ×1

foreach ×1

html ×1

methods ×1

multithreading ×1

overflow ×1

plinq ×1