Is it possible to define a local struct, within a method, in C#?

I believe it’s not permitted to define named types within a method. As to why, I’ll have to speculate. If a type is not going to be used outside, then its existence probably cannot be justified.

You can however define anonymous type variables within a method. It will somewhat resembles structures. A compromise.

public void SomeMethod ()
{
    var anonymousTypeVar = new { x = 5, y = 10 };
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)