Skip to content

Add more type-inferencing to C# #17

@kasajian

Description

@kasajian

For instance, when you have code such as:
public static int Add( int x, int y )
{
return x + y;
}

Why do you have to specify "int"? You can simply say:
public static Add( x, y )
{
return x + y;
}

I realize that's what Generics are for, and maybe that's how the above will get implemented. Note that this is not about dynamic typing. The above code very much is aware of types, but it works like generics do. Also, we'll have to have automatic handling of constraints on the implicit type parameters. You should have to specify a "where" keyword. For instance, remove the need to say something like:
where T : new()
when you see the code do a new.

So this type of code:
class ItemFactory
{
public GetNewItem()
{
return new typeof(return)();
}
}

changes into this type of code internally:
class ItemFactory where T : new()
{
public T GetNewItem()
{
return new T();
}
}

Then specifying a type in code will be mostly when you instantiate it. The rest of the code attempts to infer it.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions