C# questions because, why not?

If it's not ZDoom, it goes here.
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm

C# questions because, why not?

Post by ibm5155 »

Hey guys, here's the ansi C guy :D...

So,I still didn't found a proper way of doing this:

Code: Select all

 C code example

struct test
{
  int a,b,c;
};
void set_All_one(test *X)
{
   X->a = 1;
   X->b = 1;
   X->c = 1;
}

void main(){
   test X;
   set_All_one(&X);
   printf("%d %d %d",X->a, X->b, X->c); //output : 1 1 1
}
Also, I'm doing some kind of UWP testing software and the only way I found yet for sharing data is using some kind of global static class where everyone can use it (but that just looks so bad that I don't wanna use it everywhere).
User avatar
InsanityBringer
Posts: 3392
Joined: Thu Jul 05, 2007 4:53 pm
Location: opening the forbidden box

Re: C# questions because, why not?

Post by InsanityBringer »

I believe this is what you want

(also c# totally supports pointers in unsafe contexts, but I'm honestly not quite sure why. only ever seen it used while doing native calls)
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: C# questions because, why not?

Post by The Zombie Killer »

Code: Select all

using System;

public class Program
{
	public static void Main(string[] args) =>
		new Program().Start(args);
	
	private struct test
	{
		public int a, b, c;
	}
	
	private void set_All_one(ref test X) =>
		X.a = X.b = X.c = 1;
	
	private void Start(string[] args)
	{
		var X = new test();
		set_All_one(ref X);
		Console.WriteLine("{0} {1} {2}", X.a, X.b, X.c);
	}
}
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm

Re: C# questions because, why not?

Post by ibm5155 »

only that...
Thanks guys, that saved me alot of time :D

Return to “Off-Topic”