小编Dan*_*nM7的帖子

如何处理鼠标事件

我想点击一个正方形,然后一个"X"应该出现里面,但我不知道在里面放什么Form1_MouseDown,Form1_PaintForm1_MouseUp事件.我怎样才能实现这个C#?

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;

namespace VTest
{
    public partial class Form1 : Form
    {
        Rectangle rect; // single rect
        int sqsize, n;
        int margin;

        public Form1()
        {
            n = 3;
            margin = 25;
            sqsize = 50;
            rect = new Rectangle(10, 10, 150, 150);
            InitializeComponent();
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            // what goes here?
        }

        private void Form1_Paint(object sender, …
Run Code Online (Sandbox Code Playgroud)

c#

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

使用LINQ重写代码

这是我使用的代码的简化版本.我需要使用LINQ重写它.

class Program
{
    // Here is the ugly stuff
    static void DoStuff(int[] uidArray)
    {
        int chunkCount = (int)Math.Ceiling(uidArray.Length / 10d);

        for (int i = 0; i < chunkCount; i++)
        {
            // calculating the remaining uids.
            // this is super ugly imho, but I couldnt come up with anything better...
            int remaining = (i == chunkCount - 1) ? uidArray.Length - i * 10 : 10;

            int[] currentChunks = uidArray.Skip(i * 10).Take(remaining).ToArray();
            string[] data = GetDataForUids(currentChunks);

            foreach (string item in …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

设置对象成员时出现NullReferenceException

我运行以下程序时收到NullReferenceException.我认为问题来自于我正在创建一个Line包含Point类的事实.

using System;

class Driver
{
    static void Main()
    {
        Point pOne = new Point();
        Point pTwo = new Point(2, 1);

        Console.Write("Point pOne: ");
        PrintPoint(pOne);

        Console.Write("Point pthree: ");
        PrintPoint(pTwo);

        Line lOne = new Line(pOne, pTwo);

        Console.WriteLine("Line lOne: ");
        PrintLine(lOne);

        //Rectangle rOne = new Rectangle();
        Rectangle rOne = new Rectangle(lOne);

        Console.WriteLine("Rectangle rOne: ");
        PrintRectangle(rOne);

        Console.ReadLine();
    }

    // The PrintPoint method
    // purpose: display the coordinates of a Point
    // Parameters: a Point object
    // returns: none
    static …
Run Code Online (Sandbox Code Playgroud)

c# exception class nullreferenceexception

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

简单文件I/O - 读取新行

我有一个文件存储一类学生的考试成绩.我正在尝试编写一个程序,该程序可以成功打开文件,读取考试分数,找到平均分数,最高分数和最低分数,并打印出来.平均分数应在小数点后打印2位数.

这是我到目前为止:

static void Main()
{
    string myData = "";
    int temp = 0;
    int max = 0;
    int min = 0;
    double average = 0;
    StreamReader fileReader = new StreamReader("data.txt");

    do
    {
        myData = fileReader.ReadLine();

        if (myData != null)
        {
            max = int.Parse(myData);
            temp = int.Parse(myData);

            if (temp > max)
                temp = max;
        }

    } while (myData != null);

    fileReader.Close();
    Console.ReadLine();
}//End Main()
Run Code Online (Sandbox Code Playgroud)

我不知道如何继续.如何读取新行并将其分配给temp?我不认为我做得对.

c# file-io

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

从单个for循环生成乘法表

是否可以使用单个for循环生成乘法表(例如,从1到9)?

c# math

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

确定DateTime是否在给定的日期范围内

Aries          March 21 to April 20.
Taurus         April 21 to May 20.
Gemini         May 21 to June 21.
Run Code Online (Sandbox Code Playgroud)

我需要通过将用户的出生月份和日期作为输入来打印用户的占星符号.我如何获得日期范围?

EX:3月21日至4月20日

c# datetime

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

如何从.tps topscan Clarion文件中提取数据?

我必须从Clarion数据库创建一个MySQL数据库.这些表是.tps文件.

我不知道该怎么做,现在我只找到了与.dat文件一起使用的应用程序.

clarion tps

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

输入验证 - 数字与字母

我正在创建一个简短的C#控制台程序,它将使用0-10的随机数询问10个附加问题.然后它告诉用户他们有多少正确或不正确的答案.我试图找到一种方法来验证我的用户输入是一个数字而不是一个字母.我发布了目前为止创建的代码,但可以使用一些帮助.

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            int input;
            int correct = 0;
            int incorrect = 0;
            int questions = 10;
            int[] solutions = new int[21];
            int[] answers = new int[21];
            int[] number1 = new int[21];
            int[] number2 = new int[21]; 

            Random number = new Random();

            Console.WriteLine("  This is a test of your basic addition skills. ");
            Console.WriteLine("  Please answer the random addition …
Run Code Online (Sandbox Code Playgroud)

c# validation

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

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

生命游戏算法问题

我正在用C#编写一个生命游戏程序.我正在使用2D数组结构.似乎当我显示Random方法时,邻居或某事的算法是错误的.当它经历了几代人时,随机细胞就会变得"活着".有帮助吗?

public struct cellDetail
{
    public int curGenStatus;
    public int nextGenStatus;
    public int age;

}
public class Class1
{

    static cellDetail[,] Generations(cellDetail[,] cells)
    {

        int neighbours = 0;

        for (int i = 0; i < 40; i++)
            for (int j = 0; j < 60; j++)
                cells[i, j].nextGenStatus = 0;

        for (int row = 0; row < 39; row++)
            for (int col = 0; col < 59; col++)
            {
                neighbours = 0;

                if (row > 0 && col > 0) …
Run Code Online (Sandbox Code Playgroud)

c#

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