System.* not defined or imported

kopbeen

New member
Joined
Aug 15, 2024
Messages
2
Programming Experience
10+
Good afternoon,

a bit stumped with this one - any help would be greatly appreciated:

System.Void, System.Object, System.Inptr not defined or imported... a little bit stumped with this one... any help would be greatly be appreciated...

Regards,
Pieter Claassens
 
I deleted your duplicate post under the IDE sub-forum.

You can read about the System.Void over here: Void Struct (System) , but in general you shouldn't need to be using System.Void unless you are doing a lot of reflection code.

Most people will use the alias object instead of System.Object. Often object is used when really want a to refer to a reference type at the lowest level. Good programming practice is to use a more specific type if possible.

It looks like there is a typo with regards to System.Inptr. It should be System.IntPtr .

Can you share some minimal code that shows the problem that you are running into? Showing us the code where you are trying to use these might give us more context about what you are trying to do.
 
Hi, yes sorry for the typo for System.IntPtr... here is the line of code giving me some headaches :
C#:
   public delegate void CallbackType(bool success, TReturnType returnValue);
 
I assume that what you meant to write was:

C#:
public delegate void CallbackType<TReturnType>(bool success, TReturnType returnValue);

Can you put that code into context? The following in .NET Fiddle seems to compile and run fine without problems:
C#:
using System;
					
public class Program
{
	public delegate void CallbackType<TReturnType>(bool success, TReturnType returnValue);
	
	class Foo
	{
		public string Bar; 
	}

	static void TestMe(bool successs, Foo foo)
	{
		Console.WriteLine("In TestMe. Foo.Bar incoming as {0}", foo.Bar);
		foo.Bar = "Done";
	}
	
	static void TestFooCallback(CallbackType<Foo> action)
	{
		var foo = new Foo();
		foo.Bar = "Starting";
		Console.WriteLine(foo.Bar);

		action(true, foo);

		Console.WriteLine(foo.Bar);
	}
	
	public static void Main()
	{
		TestFooCallback(TestMe);
	}
}
 
As an aside. With your 10+ years of programming experience you are likely aware about pass-by-value vs. pass-by-reference. C# is a pass-by-value language so your TReturnType returnValue might be a misnomer. If TReturnType is a value type, there is no way for the delegate to return a value. That parameter then essentially should just be treated as an incoming default value or initial value.
C#:
public delegate void CallbackType<TReturnType>(bool success, TReturnType defaultValue) where TReturnValue : struct;

In the code example I have in post #4, I deliberately declared the class Foo so that I could pass in a reference type, and be able to change values within the instance passed in. (e.g. Bar). The returnValue parameter would be treated more like a data transfer object.

If the instance needs to be completely replaced but there needs to be a way to pass in an initial value, then marking it as ref would be more appropriate. e.g.
C#:
public delegate void CallbackType<TReturnType>(bool success, ref TReturnType value);

If the delegate's intent is truly to return a value and there is no need to pass in an initial or default value, then the parameter should be marked as out. e.g.
C#:
public delegate void CallbackType<TReturnType>(bool success, out TReturnType returnValue);

But then this also leads to another design issue. If a function only has one out parameter, and the function currently returns void, a better design would be to change the signature to return a type of that TReturnType. .e.g.
C#:
public delegate TReturnType CallbackType<TReturnType>(bool success);
 
Back
Top Bottom