Unexpected character error in C# dot net application [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a solution created in C#. i have a piece of code in it base.\u002Ector();. When i try to build the application from Visual Studio I am getting the Following error.
Unexpected character '\u002E'

Remove \u002E and you're done!
002E is a full stop or just a dot ('.').
Your code must look like:
base.ctor();
It could happen because of transmitting a program source through different websites/programs with unsupported or broken encoding.
Moreover, ctor is a shortcut for constructor. Make sure you call constructor of base class correctly.
public class Animal
{
public Animal()
{
}
}
public class Cat : Animal
{
// next line will be converted to
// base.ctor() by compiler
public class Cat() : base()
{
}
}
Try to remove base.ctor(); in order to make your class work. I think it should work because your base class has no parameters in constructor.

Related

is it bad practice that a child class does not use all parent's elements? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 days ago.
This post was edited and submitted for review 8 days ago.
Improve this question
My question is related to inheritance it.
Let say we have a class called Animal. All animals share some behaviour like walking, pooping, hunting, etc. After few days I decided to add a Fish class that extend Animal class. But here fish swims but does not hunt or walk.
Is it OK to use only some parts of the base class? Because Fish class can still calls walk and hunt but does not execute the behaviour, I guess.
I could go around the problem where i make a function called behaviour in base class and let the child class override it.
Like this:
public class Animal
{
public virtual void behaviour() {
Console.WriteLine("//do something");
}
}
public class GoldFish : Animal
{
public override void behaviour() {
Console.WriteLine("goldfish swims");
}
}
Any suggestion on how should go about this with best practices of programming?

Make a method both static and instance [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
This post was edited and submitted for review 10 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have a class called Foo and a static method - Bar (Foo instance) - inside it. But instead of only being able to call it like Foo.Bar(new Foo()), I want to also be able to say new Foo().Bar();
TL;DR I have a static method in class Foo which has a parameter of type Foo and I want to also be able to call it as if it was a non-static method.
This is all for testing purposes. I know this'd be terrible code design.
Create both methods, and let one redirect to other, where main logic is:
public class Foo
{
// Called by Foo.Bar(new Foo());
public static void Bar(Foo instance)
{
// logic here
}
// Called by new Foo().Bar();
public void Bar()
{
Foo.Bar(this);
}
}

My custom attribute not working [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to make an attribute so that I can decorate an action/controller and have some code run.
This is the code for my Attribute:
public class UpdateLastLogInAttribute : System.Attribute
{
Linq.UserMinData umd { get; set; }
public UpdateLastLogInAttribute()
{
this.umd =datafuncs.GetMinData();
if (umd != null)
datafuncs.SaveLastConnected(umd);
}
}
...and this is the Controller that I want the Attribute to work with
[funcs.UpdateLastLogIn]
public class HomeController : Controller
{
}
However, when I hit the controller, my code never executes. What's wrong?
Attributes are dumb. There isn't any magic that makes code in attributes run. It's down to you to reflect on your code and to detect the attributes and run the code.
Fortunately, MVC already does this for specific attribute types, so...
You might consider extending ActionFilterAttribute and overriding OnActionExecuting,OnActionExecuted, OnResultExecuting or OnResultExecuted depending on which phase of the request you want to intercept.
MVC looks out for subclasses of this attribute and executes the four methods above at the appropriate time.

Partial class sharing same method names [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
If a partial class has the same method name but different types I will get an error right?
public partial class Employee
{
public int sum()
{
}
}
public partial class Employee
{
public string sum()
{
}
}
Yes, it does:
'Employee' already defines a member called 'sum' with the same parameter types
Partial classes are just the same as regular class, except their definition is split in two sources. They have to comply to every rule regular classes have. That includes rules concerning the uniqueness of method signatures.

Polymorphism in c# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a problem with a class that is to spawn instances containing one out of about 30 objects of different types (I call it out_out_of_many_types_of_subcontract in the code snippet below).
class supercontract
{
void supercontract (float date, one_out_of_many_types_of_subcontract subcontract)
{
stuff....
}
}
Is there any way of declaring a semi-generic variable or must I (1) resort to polymorphism between constructors or (2) casting an object as a certain type with a block of (else)if clauses?
Cheers!
I would make them all implement a single interface.
interface IContract{}
class AContract: IContract {...}
Even if the interface is empty you can limit what types could be passed to your method.

Categories