小编UpT*_*ide的帖子

字节的二进制读取只返回一个值.C#

当我期待0,1,2,3时,控制台显示0,0,0,0.

这是以下版本的修改版本:https://msdn.microsoft.com/en-us/library/system.io.binarywriter(v=vs.110).aspx

using System;
using System.IO;

namespace testingfilereadwrite
{    
class Program
{
    const string FileName = "TestFile.dat";       
static void Main()
    {
        WriteDefaultValues();
        DisplayValues();
        Console.ReadKey();
    }        
public static void WriteDefaultValues()
    {
        using (BinaryWriter writer = new BinaryWriter(File.Open(FileName, FileMode.Create)))
        {
            writer.Write(0);
            writer.Write(1);
            writer.Write(2);
            writer.Write(3);
        }
    }

    public static void DisplayValues()
    {
        byte byte1;
        byte byte2;
        byte byte3;
        byte byte4;

        if (File.Exists(FileName))
        {
            using (BinaryReader reader = new BinaryReader(File.Open(FileName, FileMode.Open)))
            {
                byte1 = reader.ReadByte();
                byte2 = reader.ReadByte();
                byte3 = reader.ReadByte(); …
Run Code Online (Sandbox Code Playgroud)

c# arrays fileparsing

3
推荐指数
2
解决办法
98
查看次数

C#:使字段只能使用包含该字段的类进行修改

我确信在我不知道正确的表达方式之前已经有人问过这个问题,所以我找不到我要找的东西。

我有一个类,其中有一个字段,我希望能够从外部看到该字段,但无法直接修改它。

public class myclass
{
    public int value;
    public void add1()
    {
        value = value + 1;
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我真的希望只可以从方法中修改add1()“值”字段,但我仍然希望能够看到“值”的值。

编辑:我认为只能通过类进行修改myclass,但我输入了其他内容。感谢您指出了这一点。

c# encapsulation class

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

使用基于枚举值的函数?

这就是我用来根据枚举类型选择函数的方法。有没有我没有切换CalcMe功能的方法?

namespace ClassLibrary1
{
public class Playbox
{
    //types:
    //0 - red hair
    //1 - blue hair

    //defines function to input based on hairtype.
    //red:
    // input*10
    //blue:
    // input*12

    public enum Phenotypes
    {
        red,
        blue
    }

    static public int Red(int input)
    {
        return input*10;
    }

    static public int Blue(int input)
    {
        return input*12;
    }

    static public int CalcMe(Phenotypes phenotype, int input)
    {
        switch (phenotype)
        {
            case Phenotypes.red:
                return Red(input);
            case Phenotypes.blue:
                return Blue(input);
            default:
                return 0;
        } …
Run Code Online (Sandbox Code Playgroud)

c# enums

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

Oracle 星期几(无字符串比较)

我会在前面说我发现的所有文档都不适用于我的 Oracle 版本: https: //docs.oracle.com/cd/E51711_01/DR/WeekDay.htmlhttps://docs.oracle.com/cd/E37483_01/server.751/es_eql/src/ceql_functions_date_extract.html

或者我可以使用的函数参考不要提及星期几: https ://docs.oracle.com/cd/B28359_01/server.111/b28286/functions052.htm#SQLRF00639

所以我只是想办法使用to_char来做到这一点,然后进行 varchar2 比较。如果可能的话,我想坚持使用日期格式。

到目前为止这是我的sql

select dateSold from sales
where extract(dateSold, day_of_week) in (1, 3, 4, 7)

SQL Error: ORA-00904: "DAY_OF_WEEK": invalid identifier
Run Code Online (Sandbox Code Playgroud)

sql oracle oracle11g

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

标签 统计

c# ×3

arrays ×1

class ×1

encapsulation ×1

enums ×1

fileparsing ×1

oracle ×1

oracle11g ×1

sql ×1