小编Voj*_*ech的帖子

带直方图的 C# 级数组

我正在瑞典学习 C# 基础编程,我想知道您是否可以帮助我理解一个简单的示例。

我的目标是用随机数填充数组,然后显示星号 (*) 或任何符号,其次数与随机生成的数字相同。

这就是我的意思:

Student 1 has a grade: 4 : * * * *
Student 2 has a grade: 9 : * * * * * * * * *
etc.
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止想出的代码:

using System;
using System.Text;

namespace Array_1_10
{
    class Program
    {
        static void Main(string[] args)
        {
            //declar and create an int array object with 5 elements

            string tempStars = "";
            int[] grades = new int[11];
            // initiate the array using Random class methods
            Random grade …
Run Code Online (Sandbox Code Playgroud)

c# arrays

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

C#向文本文件添加行号

我正在尝试在 C# 中读取文本文件并将行号添加到行中。

这是我的输入文件:

    This is line one
    this is line two
    this is line three
Run Code Online (Sandbox Code Playgroud)

这应该是输出:

    1 This is line one
    2 this is line two
    3 this is line three
Run Code Online (Sandbox Code Playgroud)

到目前为止,这是我的代码:

class Program
{
    public static void Main()
    {
        string path = Directory.GetCurrentDirectory() + @"\MyText.txt";

        StreamReader sr1 = File.OpenText(path);

        string s = "";

        while ((s = sr1.ReadLine()) != null)           
        {
            for (int i = 1; i < 4; i++)
                Console.WriteLine(i + " " + s);
            }

            sr1.Close();
            Console.WriteLine(); …
Run Code Online (Sandbox Code Playgroud)

c# streamwriter streamreader

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

symfony2 多对多奏鸣曲管理 model_list

我正在使用最新的 Symfony2 和 Sonata Admin 来维护我的网站,这是我的问题:

\n\n

我有两个实体:商店和折扣。一个店铺可以有多个折扣,一个折扣可以分配给多个店铺。因此它应该是多对多关系。

\n\n

我想在 ShopAdmin 中使用 sonatata 的 type_model_list,这样我就可以从弹出窗口中选择这些折扣并选择多个。这可能吗?

\n\n

这是我的商店实体的一部分:

\n\n
use Doctrine\\Common\\Collections\\ArrayCollection;   \n ...\n/**\n * @var \\Doctrine\\Common\\Collections\\ArrayCollection\n * @ORM\\ManyToMany(targetEntity="ShoppingFever\\ShoppingFeverBundle\\Entity\\Discount", fetch="EAGER")\n * @ORM\\JoinColumn(name="discountId", referencedColumnName="id")\n */\nprivate $discountId;\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是函数configureFormFields的相对ShopAdmin:

\n\n
$formMapper\n        ->add(\'shopName\',null, array(\'label\' => \'N\xc3\xa1zev obchodu\'))\n        ->add(\'brandName\',null, array(\'label\' => \'N\xc3\xa1zev brandu\'))\n        ->add(\'discountId\', \'sonata_type_model_list\', array(\n            \'btn_add\'       => \'Add discount\',      //Specify a custom label\n            \'btn_list\'      => \'button.list\',     //which will be translated\n            \'btn_delete\'    => false,             //or hide the button.\n            \'btn_catalogue\' => \'SonataNewsBundle\' //Custom translation domain …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm sonata-admin

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

C#将XML转换为字符串以便搜索它

我正在尝试搜索XML文档以获取特定信息.在程序的第一部分,我将所有信息从XML显示到控制台(这很简单,我已经完成了),在第二部分,我试图在节点之间搜索特定信息,以便在控制台上显示它.我也这样做了,但我不知道如何从XML文件(order.xml)读取XML并将其转换为字符串以便使用它.

这是我的代码:

order.xml

<?xml version="1.0" encoding="utf-8" ?>
<ordercat>
  <order order_ID="1" employee_ID="125">
    <CustomerId>1</CustomerId>
    <OrderDate>19.12.2009</OrderDate>
    <ShippedDate>21.12.2011</ShippedDate>
    <ShipName>Sven Skanske</ShipName>
    <ShipAddress>Stockholm 542, Stockolm</ShipAddress>
    <ShipCountry>Sweden</ShipCountry>
  </order>
  <order order_ID="2" employee_ID="145">
    <CustomerId>5</CustomerId>
    <OrderDate>25.10.2010</OrderDate>
<ShippedDate>31.10.2010</ShippedDate>
<ShipName>Jan Hoznovski</ShipName>
<ShipAddress>Warsawska 212, Warsaw</ShipAddress>
<ShipCountry>Poland</ShipCountry>
  </order>
  <order order_ID="3" customerID="4" employee_ID="112">
    <CustomerId>4</CustomerId>
    <OrderDate>15.10.2011</OrderDate>
    <ShippedDate>16.10.2011</ShippedDate>
    <ShipName>Martin Petrzilka</ShipName>
    <ShipAddress>U Hrocha 2145, Sedlcany</ShipAddress>
    <ShipCountry>Czech Republic</ShipCountry>
  </order>
</ordercat>
Run Code Online (Sandbox Code Playgroud)

这是C#代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Xml;
using System.Xml.XPath;

namespace XML
{
    class Program
    {
        static void Main(string[] args)
        {
            DataSet ds = …
Run Code Online (Sandbox Code Playgroud)

c# xml string

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

控制台中派生类的顺序

我的最后一个问题是C#中的继承.我以为我理解了这个话题,但不知怎的,我错过了为什么输出是这样的.

这是我的课程:

BaseClass的:

public abstract class Vehicle
{
    public Vehicle()
    {
        Console.WriteLine("Honda Civic");
    }

    public abstract void Display();

}
Run Code Online (Sandbox Code Playgroud)

衍生的1级:

public class Vehicle4Wheels : Vehicle
{
    public override void Display()
    {
        Console.WriteLine("Derived111 class Constructor.");
    }
}
Run Code Online (Sandbox Code Playgroud)

派生类2:

public class SportCar : Vehicle4Wheels
{
    public new void Display()
    {
        Console.WriteLine("Derived222 class Constructor.");
        base.Display();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是层次结构:基类 - >派生类1 - >派生类2

这是我得到的输出:

Honda Civic
Derived222 class Constructor.
Derived111 class Constructor.
Run Code Online (Sandbox Code Playgroud)

这是我想要实现的输出:

Honda Civic
Derived111 class Constructor.
Derived222 class Constructor.
Run Code Online (Sandbox Code Playgroud)

我已经阅读了几篇文章,其中声明基类首先打印,其他派生类根据它们在层次结构中的位置打印.

那么为什么最后一个派生类在第一个派生类之前打印出来?我缺少什么(除了C#编程技巧)?

谢谢你的回答. …

.net c# inheritance

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

drscheme - 有限状态机

感谢在这个伟大的网站上的人们,我设法将几乎完整和有效的代码放在一起.我有一个最后的问题.

这是代码:

     (define (chartest ch)
       (lambda (x) (char=? x ch)))

     (define fsm-trans
        '((A (lambda (x) (string=? x "a") B), (B (lambda (x) (string=? x "a") C)))))

     (define (find-next-state state ch trl)
       (cond
         [(empty? trl) false] 
         [(and (symbol=? state (first (first trl)))
              ((second (first trl)) ch))
          (third (first trl))]
         [else (find-next-state state ch (rest trl))]))


     (define fsm-final '(C))

     (define start-state 'A)

     (define (run-fsm start trl final input)
       (cond
         [(empty? input)
          (cond
            [(member start final) true]
            [else false])]
         [else 
          (local ((define next …
Run Code Online (Sandbox Code Playgroud)

scheme fsm racket

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