小编The*_*kis的帖子

为什么`*(multi + row)`生成指针地址而不是值?

为什么要*(multi + row)生成指针地址而不是值?我很困惑,但必须有一个很好的解释,但我不知道.

#include <stdio.h>
#define ROWS 5
#define COLS 10
int multi[ROWS][COLS];
int main(void)
{
    int row, col;
    for (row = 0; row < ROWS; row++)
    {
        for (col = 0; col < COLS; col++)
        {
            multi[row][col] = row*col;
        }

    }
    for (row = 0; row < ROWS; row++)
    {
        for (col = 0; col < COLS; col++)
        {
            printf("\n%d ",multi[row][col]);
            printf("%d ",*(*(multi + row) + col));
        }
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c pointers multidimensional-array

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

C#如何解决不同的扩展方法重载?

我有一个代码片段如下:

public static class M
{
    public static int Plus(this int i, int p=6)
    {
        return i + p;
    }
}
public static class N
{
    public static int Plus(this int i)
    {
        return i + 10;
    }
}
class Program
{
    static void Main()
    {
        int i = 3.Plus();
        Console.WriteLine(i);
    }
}
Run Code Online (Sandbox Code Playgroud)

运行程序,输出"13",表示调用N类的扩展方法.为什么M类的方法不匹配?

然后,如果我删除N类,OK,调用类M的扩展方法,它会按预期输出"9".

所以我的问题是,是否有一个规则在C#或.net框架中确定,如果有多个匹配,将调用哪个扩展方法?这是否与重载解析规则或其他相关?

非常感谢.

c# overloading match

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

初始化变量

声明中Method1和Method2的区别是什么?

方法1

private readonly CategoryBusiness _categoryBusiness = new CategoryBusiness();
Run Code Online (Sandbox Code Playgroud)

方法2

private readonly CategoryBusiness _categoryBusiness;

public CategoryController() : this(new CategoryBusiness())
{

}

public CategoryController(CategoryBusiness categoryBusiness)
{
    _categoryBusiness = categoryBusiness;
}
Run Code Online (Sandbox Code Playgroud)

更新: 我的确切问题是

在其声明中初始化一个只读字段与在构造函数中使用相同值初始化它是一样的吗?

c#

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

什么是性能关键热点及其目的?

在Nutshell(O'Reilly)中阅读C#5.0,在第一章中有一节讨论内存管理.本节介绍了C#中指针的不必要用法,因为它消除了其他语言(如C++)中指针不正确的问题.最后,它提到了性能关键热点中指针的关键用法.

那么,什么是性能关键的热点及其目的呢?

在此先感谢您的帮助.

c# performance pointers

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

为什么ClassLoader是一个抽象类?

ClassLoader是一个抽象类,即使它没有任何抽象方法.为什么会这样?没有抽象方法还有其他抽象类吗?

java abstract-class classloader

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

C++有没有办法让程序运行得更快?

例如..如果我有.

#include <iostream>
using namespace std;

int main()
{
   int counter = 0;
   while (true)
   {
      cout << counter << endl;
      counter++
   }
}
Run Code Online (Sandbox Code Playgroud)

并且说我在与其他计算机竞争10亿的竞争中,这个循环的运行速率纯粹取决于计算机处理器的速度?或者我的程序运行速度有限制,这可能是多变的?

c++ performance iostream loops

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

如何解决Java中的"无法解决变量"错误?

我想知道是否有人可以帮我弄清楚为什么我的程序一直告诉我seperate_numbers无法解析为变量.还有什么类型我必须分配Seperate_number以使该程序工作.它必须包含两个方法头public static void seperate_number(int integer)和public static int intGetNum.

谢谢你的帮助

import java.util.*;

public class Deprey_J_prog1
{
    static Scanner console = new Scanner (System.in);

    public static void main (String[] args)
    {
        int main_Number;
        main_Number =  intGetNum();
        Seperate_number = main_Number;
    }

    static int num, b, a, integer;

    public static int intGetNum()
    {
        int ret_val = 0;
        System.out.print("please enter a 5 integer number");
        integer = console.nextInt();
        return ret_val;
    }

    public static void Seperate_number(int integer)
    {
        for (a = 1; a <=5; a++)
        {
            for …
Run Code Online (Sandbox Code Playgroud)

java

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

如何在C#中编写最佳Swap(T a,T b)算法?

我在这个孤独的星期五晚上的任务是写一个C#交换算法

public void Swap<T> ( ref T a, ref T b ) 
{
   // ... 
} 
Run Code Online (Sandbox Code Playgroud)

适用于任何类或数据类型T,并尽可能高效.帮助批评我到目前为止建立的方法.首先,这是正确的吗?我如何才能使其获得Skeet认证?

public void Swap<T> ( ref T a, ref T b ) 
{
   // Not sure yet if T is a data or value type. 
   // Will handle swapping algorithm differently depending on each case.
   Type type = T.GetType();
   if ( (type.IsPrimitive()) || (type == typeof(Decimal)) )
   {
       // this means the we can XOR a and b, the fastest way of …
Run Code Online (Sandbox Code Playgroud)

.net c# algorithm optimization

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

为什么C不允许结构中的成员函数?

C和C++之间的一个重大区别是结构中的成员函数.C不允许函数作为结构中的成员.我知道一个解决方法是使用函数指针作为结构成员,但这只是函数模拟,它打破了范围规则.

如果C允许实际函数作为结构的成员,那将是一个很好的功能.但我不知道为什么C不这样做.有什么特别的原因吗?

c struct

-9
推荐指数
2
解决办法
101
查看次数