小编Wes*_*ron的帖子

如何使用StreamWriter写入文件?

在我的Wpf应用程序中,我使用的是Person类(即基类),它包含一个虚方法SaveData(),以及其他继承自Person的类Client.如何覆盖方法SaveData()并保持数据从基数?

班级人员

public virtual void SaveData()
{
   string arqName = string.Format("Person{0}" + ".txt", Id);
   StreamWriter file = new StreamWriter(arqNome);
   file.WriteLine("ID: " + Id);
   file.WriteLine("DOB: " + dOB);
   file.WriteLine("Name: " + name);
   file.WriteLine("Age: " + age);
   file.Flush();
   file.Close();     
}
Run Code Online (Sandbox Code Playgroud)

类客户

public override void SaveData()
{
   base.SaveData();
   string arqName = string.Format("Person{0}" + ".txt", Id);
   StreamWriter file = new StreamWriter(arqNome);
   file.WriteLine("Cod: " + cod);
   file.WriteLine("Credits: " + credits);
   file.Flush();
   file.Close();
}
Run Code Online (Sandbox Code Playgroud)

客户端中的覆盖方法确实覆盖了其他数据,如Name,Age,DOB ......我需要在同一个文件中保留两者.

.net c# io streamwriter

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

如何通过鼠标点击在画布上绘制多边形?纯JS

我需要在我的画布上绘制一个多边形,但我必须通过点击鼠标来完成。例如:单击一次单击两棵树等等...最多十次单击并应用一条线来填充所有单击的点。纯JS。

function drawPolygon(position, sides, angle) {
    var coordinates = [],
        radius = Math.sqrt(Math.pow((dragStartLocation.x - position.x), 2) + Math.pow((dragStartLocation.y - position.y), 2)),
        index = 0;

    for (index = 0; index < sides; index++) {
        coordinates.push({x: dragStartLocation.x + radius * Math.cos(angle), y: dragStartLocation.y - radius * Math.sin(angle)});
        angle += (2 * Math.PI) / sides;
    }

    context.beginPath();
    context.moveTo(coordinates[0].x, coordinates[0].y);
    for (index = 1; index < sides; index++) {
        context.lineTo(coordinates[index].x, coordinates[index].y);
    }

    context.closePath();
}
Run Code Online (Sandbox Code Playgroud)

html javascript canvas mouseevent polygons

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

C#如何保存big big int?

我需要从字符串转换此值:4248035245857302861304475122262852382232831183377907185400973044372526725256648804647567360并将其保存在int中.长,Int64数据类型不起作用.我不能使用BigInteger.双人不能分.一些建议?

    string valorLido;            
            while ((valorLido = Console.ReadLine()) != null)
            {
                int leapYear = 0;
                int huluculuFestival = 0;
                int bulukuluFestival = 0;

                long ano = long.Parse(valorLido); 

                if ((ano % 4 == 0) && (ano % 100 != 0 || ano % 400 == 0))
                    leapYear = 1;
                if (ano % 15 == 0)
                    huluculuFestival = 1;
                if (leapYear == 1 && ano % 55 == 0)
                    bulukuluFestival = 1;

                if(leapYear == 1)
                    Console.WriteLine("This is leap year.");
                if(huluculuFestival == …
Run Code Online (Sandbox Code Playgroud)

c# int biginteger

-6
推荐指数
1
解决办法
124
查看次数

标签 统计

c# ×2

.net ×1

biginteger ×1

canvas ×1

html ×1

int ×1

io ×1

javascript ×1

mouseevent ×1

polygons ×1

streamwriter ×1