Reputation: 273
i have console application in that i create class then i create some functions and i call that function in program class
one is
public class student
{
public string Lastname { get; set; }
public List<int> scores { get; set; }
}
public void example2
{
List<student> std = new List<student>
{
new student {Lastname="ALI",scores=new List<int>{97, 72, 81, 60}},
new student{Lastname="abc",scores=new List<int>{75, 84, 91, 39}},
new student {Lastname="shan",scores=new List<int>{12,34,6,23,434}},
new student{Lastname="ahmad",scores=new List<int>{34,23,45,34}}
};
var sq = from stud in std
from scor in stud.scores
where scor > 90
select new { last = stud.Lastname, scor };
Console.WriteLine("Scorequery");
foreach (var stdquery in sq)
{
Console.WriteLine("{0}Score:{1}", stdquery.last, stdquery.scor);
}
Console.WriteLine("Exit");
Console.ReadLine();
}
another example
public void example2
{
int[] numbers = { 0, 1, 2, 3, 4, 5, 6 };
var q1 = from q2 in numbers
where q2 < 5
select q2;
foreach (int i in q1)
{
Console.WriteLine(i + "");
}
Console.ReadLine();
}
now error occur on int[] is
A get or set accessor expected
where as i create get set public
same with another function and error occur on this line
List<student> std = new List<student>
and another function on this line
char[] uppercase = { 'A', 'B', 'C' };
Upvotes: 0
Views: 374
Reputation: 5771
In C#, methods must have parameter lists in parantheses, i.e.
public void example()
instead of
public void example
Without the parantheses, the compiler thinks you were creating a property and thus expects a getter or setter.
Upvotes: 2
Reputation: 7579
You missed the parentheses after your example2
function definition name. It should be public void example2()
and not public void example2
.
When you define a method, you need to place parentheses after the method name. When you define an entity with braces but without parentheses, the compiler thinks that you are defining a property, like you do in the class student
.
Even if you don't have any parameters for the method, the definition must contain parentheses.
Upvotes: 3