小编som*_*ing的帖子

为什么普通的类实例化会导致未处理的溢出异常?

除了初始化的普通类之外,我看不到任何其他内容.

这是类,类Bet.cs:

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

namespace Lab_ADayAtTheRaces
{
public class Bet : Form1
{
    public int Bets_Joe;
    public int Bets_Bob;
    public int Bets_Al;
    public int Dog_Joe;
    public int Dog_Bob;
    public int Dog_Al;

    public int Amount;
    public int Dog;
    public Guy Bettor;

    public string GetDescription()
    {
        Amount = (int)numericUpDownBucksToBet.Value;
        Dog = (int)numericUpDownDogToBetOn.Value;
        //Bettor =
        return Bettor + " placed a bet in the amount of " + Amount + " bucks on dog number …
Run Code Online (Sandbox Code Playgroud)

c# stack-overflow exception class

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

为什么这个随机Next()会抛出异常?

嗨,我是编程新手,正在阅读本书.这是其中一章的结尾处的练习.但我的代码抛出了这个异常.

        Random rand = new Random();
        List<int> numbers = new List<int>();

        for (int i = 0; i < 1000; i++)
        {
            numbers[i] = rand.Next(1, 1001);
        }

        for (int i = 0; i < numbers.Count; i++)
        {
            listBox1.Items.Add(numbers[i]);
        }
Run Code Online (Sandbox Code Playgroud)

这是错误: 在此输入图像描述

c# random for-loop exception

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

无法在if else中声明对象.if else子句以外不可见

当我在if/else子句中实例化Textwriter对象时,它在子句外部是不可见的.我能在这做什么?我想要附加或写一个新文件.

这是代码:

     private static void eventfull_doing()
    {
        string path, line;
        int countLines;
        Console.Write("Enter the name(with extension) of the file in the \"data\" folder, or create a new name(with extension): ");
        path = Console.ReadLine();
        TextReader inFile = new StreamReader(@"C:\data\" + path);
        Console.Write("How many lines of text do you want to add to the file?: ");
        countLines = Convert.ToInt32(Console.ReadLine());
        if (inFile.Peek() == -1 || inFile == null)
        {
            TextWriter outFile = File.AppendText(@"C:\data\" + path);
        }
        else
        {
            TextWriter outFile = new StreamWriter(@"C:\data\" …
Run Code Online (Sandbox Code Playgroud)

c# if-statement object declare

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

扩展方法.错误没有方法'WriteTextToConsole'的重载需要1个参数

我正在学习C#和C,这个C#代码给我一个我不明白的错误.我正在阅读有关扩展方法的内容,这段代码给出了错误:方法'WriteTextToConsole'没有重载需要1个参数.如您所见,它只需要1个参数?我创建变量c和count只是为了能够构造字符串对象.所以我可以在String类中尝试扩展.是否理解您创建扩展方法的方式:是在参数前面加上"this"关键字,参数是要扩展的类的类型?

代码在这里:

        Console.WriteLine();
        M.WriteTextToConsole("Hello, world. Programming in C# is fun");
        char c = 'A';
        int count = 14;
        String str = new String(c, count);
        str.WriteTextToConsole("This is a string");
Run Code Online (Sandbox Code Playgroud)

方法在这里:

static class M
{
  public static void WriteTextToConsole(this string text)
  {
      Console.WriteLine(text);
  }
}
Run Code Online (Sandbox Code Playgroud)

c# parameters methods extension-methods this

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

错误CS1729:类型`System.Collections.Generic.List <string>'不包含带有'5'参数的构造函数

我正在学习C和C#,这个问题适用于C#.这个问题是书中的代码,代码不能编译,错误是:错误CS1729:类型System.Collections.Generic.List<string>' does not contain a constructor that takes5'参数.

这是代码:

    public static void Main (string[] args)
    {
        List<string> names = new List<string>("Christa ",
                                          "  Sarah",
                                          "Jonathan",
                                          "Sam",
                                          " Schmekowitz");
Run Code Online (Sandbox Code Playgroud)

c# constructor compiler-errors list

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