///Calling Class
public class Student
{
public void PrintList()
{
var wg = new WebGrid();
wg.Print(new List<Student>(), 1, 100, "Name", "ASC");
}
}
///Called Class
public class WebGrid
{
//Main Method
internal void Print(List<Student> list, int page, int size, string sortBy, string sortDirection)
{
//No Error
throw new NotImplementedException();
}
//You Want
internal void Print(List<Student> list, int page, int size, string sortBy = "Name", string sortDirection)
{
//Error , Optional parameters must appear after all required parameters
throw new NotImplementedException();
}
//Your Solution
internal void Print(List<Student> list, int page, int size, string sortBy = "Name", string sortDirection = "")
{
//Just make the sortDirection as optional Parameter
throw new NotImplementedException();
}
// Another Solution
internal void Print(List<Student> list, int page, int size, [Optional, DefaultParameterValue("Name")] string sortBy, string sortDirection)
{
// No Error, Its uses Reflection
throw new NotImplementedException();
}
}
public class Student
{
public void PrintList()
{
var wg = new WebGrid();
wg.Print(new List<Student>(), 1, 100, "Name", "ASC");
}
}
///Called Class
public class WebGrid
{
//Main Method
internal void Print(List<Student> list, int page, int size, string sortBy, string sortDirection)
{
//No Error
throw new NotImplementedException();
}
//You Want
internal void Print(List<Student> list, int page, int size, string sortBy = "Name", string sortDirection)
{
//Error , Optional parameters must appear after all required parameters
throw new NotImplementedException();
}
//Your Solution
internal void Print(List<Student> list, int page, int size, string sortBy = "Name", string sortDirection = "")
{
//Just make the sortDirection as optional Parameter
throw new NotImplementedException();
}
// Another Solution
internal void Print(List<Student> list, int page, int size, [Optional, DefaultParameterValue("Name")] string sortBy, string sortDirection)
{
// No Error, Its uses Reflection
throw new NotImplementedException();
}
}
No comments:
Post a Comment