小编Ian*_*ien的帖子

返回语句,值 - 它们是如何使用的?

我对C中的return语句有点困惑.我在C的大学介绍类中,我们已经学习了函数,但是我仍然不太明白返回值的用途.你能用它做什么?价值在哪里?例如,

#include <stdio.h>

int add(int, int);

int main()
{
    int x=0, y =0, z;
    // insert code here...
    printf("Enter a number: ");
    scanf("%d", &x);

    printf("Enter another number: ");
    scanf("%d", &y);

    z = add(x,y);
    printf("%d\n", z);

    return z;
}

int add(int x, int y)
{
    int sum;
    sum = x + y;
    return sum;
}
Run Code Online (Sandbox Code Playgroud)

由于printf函数,仅显示总和.怎么了return z?你能以某种方式将返回值传递给其他函数吗?

c return function return-value

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

我应该将CUSIP定义为什么数据库类型?

如果CUSIP定义为

CUSIP是一个9个字符的字母数字代码,用于识别北美金融证券,以促进交易的清算和结算.

那我应该在SQL Server数据库中设置什么类型?我需要考虑哪些因素?

sql sql-server finance

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

有没有办法取消鼠标点击事件

我想要取消鼠标单击,鼠标按下或鼠标按下,即使它出现在我的.NET控件上.

我希望有一个取消参数,EventArgs但我没有看到像TreeView.BeforeCheck.

还有其他方法可以做到这一点或我应该听的其他事件吗?

c# events winforms

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

catch关键字如何确定抛出的异常类型?

catch关键字如何确定抛出的异常类型?选择执行哪个catch块会发生什么过程?

try
{
    int[] myArray = new int[0];
    myArray[1] = 0;
}
catch (IndexOutOfRangeException ex) { } // how does the CLR know to enter here?
catch (InvalidCastException ex) { }
Run Code Online (Sandbox Code Playgroud)

通过ILdasm

.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint
  // Code size       28 (0x1c)
  .maxstack  3
  .locals init (int32[] V_0,
           class [mscorlib]System.IndexOutOfRangeException V_1,
           class [mscorlib]System.InvalidCastException V_2)
  IL_0000:  nop
  .try
  {
    IL_0001:  nop
    IL_0002:  ldc.i4.0
    IL_0003:  newarr     [mscorlib]System.Int32
    IL_0008:  stloc.0
    IL_0009:  ldloc.0
    IL_000a:  ldc.i4.1
    IL_000b:  ldc.i4.0 …
Run Code Online (Sandbox Code Playgroud)

.net c# exception try-catch

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

如何让我的精灵跳?(XNA,C#)

我一直在使用XNA进行简单的平台游戏.我在制定一个好的跳跃算法时遇到了一些麻烦.在摆脱了跳跃算法的凌乱半完成版本后,我剩下的就是.

if (keystate.IsKeyDown(Keys.W))
{
    spritePosition.Y = spritePosition.Y - 10;
}
Run Code Online (Sandbox Code Playgroud)

我意识到这是一个非常简单的开始,但任何提示都会很棒.我是一名自学成才的程序员,因此我可能会遗漏一些术语,我倾向于将实际代码看作是最好的学习方法.谢谢.

c# xna sprite

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

使用Statement和Entity Framework

只要我不使用注释掉的using语句,以下代码就可以工作.当我用using我得到The operation cannot be completed because the DbContext has been disposed

public IQueryable<DTOs.FormQuestionDTO> GetForm(int id, int page = 0)
{
    // FS stores pages starting with 1
    page = page == 0 ? 1 : page;

    //using (var db = new Models.FormEntities())
    //{
        var db = new Models.FormEntities();

        var questions = from fq in db.FormQuestions
                        join q in db.Questions on fq.QuestionId equals q.QuestionId
                        where (fq.FormId == id) && (fq.PageNumber == page) && fq.Disabled == false …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework

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

如何删除为普通I/O打开的文件?

如何删除为普通I/O打开的文件?

我想解密文件.如果代码不正确,那么我需要删除输出文件.

我不能用,File.Delete()因为:

Windows NT 4.0平台注意:删除不会删除为普通I/O打开的文件或内存映射的文件.

try
{
    FileStream fsIn = new FileStream(fileIn, FileMode.Open, FileAccess.Read, FileShare.Delete);
    FileStream fsOut = new FileStream(fileOut, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Delete);

    PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password, new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
    Rijndael alg = Rijndael.Create();

    alg.Key = pdb.GetBytes(32);
    alg.IV = pdb.GetBytes(16);

    CryptoStream cs = new CryptoStream(fsOut, alg.CreateDecryptor(), CryptoStreamMode.Write);

    int bufferLen = 4096;
    byte[] buffer = new byte[bufferLen];
    int bytesRead;

    do
    {
        bytesRead = fsIn.Read(buffer, 0, …
Run Code Online (Sandbox Code Playgroud)

c# stream

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

IEnumerable添加项目?

模型

public class ChartData
{
    public IEnumerable<Series> Series { get; set; }
    public string[] Categories { get; set; }
}

public class Series
{
    // there is another types
}
Run Code Online (Sandbox Code Playgroud)

我有两个数据ChartData类型

// I debugged the following, data is like my expected.
chartData = HighchartsManager.GetBranchsMeterReadingsChartData(); 
chartDataCustomerAvg = HighchartsManager.GetCustomerAvgChartData();
Run Code Online (Sandbox Code Playgroud)

我尝试连接这两个结构的系列,如下所示

// chartData.Series.Count > 3
// chartData.Series.Count > 2
// I want chartData.Series > 5 (3+2), after following line
chartData.Series.Concat(chartDataCustomerAvg.Series);
Run Code Online (Sandbox Code Playgroud)

但是没有变化chartData.Series.我怎样才能添加IEnumerable到另一个?

linq ienumerable add

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

有没有办法隐藏ToolStripMenuItem上的箭头?

有没有办法隐藏箭头ToolStripMenuItem?箭头括在红色方块中.

截图

c# winforms

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

C#创建多个自定义异常?

试图在c#中创建我的前几个自定义异常我真的不了解MSDN文章以及为什么它们有多个相同的实例

 public class CustomException : Exception
 {     
     public CustomException(): base() { }

     public CustomException(some message): base() { }
 }
Run Code Online (Sandbox Code Playgroud)

等等

我想做的是以下内容

 public class CustomException : Exception
 {     
     public AlreadySentException() : base () { }

     public InvalidMessageException() : base() { }
 }
Run Code Online (Sandbox Code Playgroud)

我只是希望能够调用这些异常.

关于如何实现这一点的想法/建议将不胜感激.

谢谢

c# asp.net-mvc exception

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