我正在练习使用C#中的指针(通过不安全的代码).所以现在,我只想将""连接到一个int*,所以我可以将它用作参数Console.WriteLine().
static void Main(string[] args)
{
fullOfPointers();
}
static unsafe void fullOfPointers()
{
int value = 10;
int* adress = &value;
Console.WriteLine(&value+"");//error
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
但编译器说运算符'+'不能用于int*和string.所以我该怎么做?
如何在datagridview中删除具有指定索引的行?所以,如果我想删除索引[2]的行,那我该怎么做?
我试过了:
for (int i = 0; i < dg1.Rows.Count; i++)
{
if (i == 2)//if iteration has reached index 2
{
dg1.Row[i].Delete;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Winforms
如何将秒转换为自定义Time结构?
struct Time
{
public int hr;
public int min;
public int sec;
}
Run Code Online (Sandbox Code Playgroud)
是否有可以执行此操作的库函数或我是否必须自己实现函数?
我正在尝试编写一个函数来查找2个数字的gcd,使用我在这里找到的Euclid算法.
从较大的数字中,尽可能多地减去较小的数字,直到您的数字小于小数字.(或者没有得到否定答案)现在,使用原始的小数字和结果,一个较小的数字,重复该过程.重复此操作直到最后一个结果为零,GCF是倒数第二个小数结果.另请参阅我们的Euclid算法计算器.
示例:找到GCF(18,27)
27 - 18 = 9
18 - 9 = 9
9 - 9 = 0
因此,最大公因子18和27是9,这是我们达到0之前的最小结果.
按照这些说明我写了一个函数:
int hcf(int a, int b)
{
int small = (a < b)? a : b;
int big = (a > b)? a : b;
int res;
int gcf;
cout << "small = " << small << "\n";
cout << "big = " << big << "\n";
while ((res = big - small) > small && res > 0) …Run Code Online (Sandbox Code Playgroud) 我有这个清单:
List<string> x=new List<string>
Run Code Online (Sandbox Code Playgroud)
所以,现在我想在计数增加时做点什么.我试过了:
if(x.Count++){
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
但它没有用.那我该怎么办呢?
所以我有这些列表:
List<Double> myDoubList1 = new LinkedList<>();
myDoubList1.Add(100);
myDoubList1.Add(66.7);
List<Double> myDoubList=new LinkedList<>();
myDoubList.Add(3);
double g=myDoubList[0]*myDoubList1[0];//error
Run Code Online (Sandbox Code Playgroud)
但是在最后一行,它有一个错误:需要数组,但List找到错误.
为什么它给我这个错误?
我试图在我的图形中添加一个新的顶点,它将添加它以便按字母顺序排列.但是,我一直遇到分段错误.我尝试使用调试器和valgrind,但它只告诉我导致seg错误的方法,我的add_vertex.
/* Adds a vertex with element new_vertex */
int add_vertex(Graph *graph, const char new_vertex[])
{
Vertex *new, *curr = graph -> vertices, *prev;
if ( has_vertex (*graph, new_vertex) || graph == NULL)
return 0;
for (prev = graph->vertices; curr = prev->next; prev = curr)
if (curr->element > new_vertex)
break;
new = malloc ( sizeof ( Vertex ) );
new->element = ( char *) malloc ( sizeof ( strlen ( new_vertex ) + 1) );
strcpy ( new -> element, …Run Code Online (Sandbox Code Playgroud) 我有以下链表:
struct node {
int d;
struct node *next;
};
int main()
{
struct node *l = 0;
struct node *k = l;
k = malloc(sizeof(struct node));
/* l->d = 8; */
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么注释代码使用错误?我不明白为什么内存没有分配给k指向同一个节点的节点l,我使用k-pointer为它分配内存.
我以为我可以将字符串指针传递给函数:
int main()
{
const char fileName[] = "network/fileName.yo";
WriteFile(fileName);
}
int WriteNetwork(char* fileName)
{
printf("the filename is %s\n", fileName);
}
Run Code Online (Sandbox Code Playgroud)
但这似乎不像我期望的那样有效.我必须错过一些非常简单的东西,但似乎无法追踪它!