|
Simplified class structure:
interface InterfaceA
{
List<InterfaceC> D{get;};
}
interface InterfaceC
{
}
class ClassE : InterfaceA
{
List<InterfaceC> PropertyD
{
get
{
return new List<InterfaceC>(MethodThatReturnsListOfTypeClassF());
}
}
class ClassF : InterfaceC
{
}
If you have a better idea on how to do it, I'm all ears, though I think this approach will do just fine.
|
|
|
|
|
It really depends on how you're using the list returned from InterfaceA.D , and how painful it would be to change the type.
Assuming you're not writing to the returned list, and you're using .NET 4.5, then this might be simpler:
interface InterfaceA
{
IReadOnlyList<InterfaceC> D { get; }
}
class ClassE : InterfaceA
{
public IReadOnlyList<InterfaceC> D
{
get { return MethodThatReturnsListOfTypeClassF(); }
}
}
If you're only using the value in a foreach loop, or passing it to methods which take an IEnumerable<T> , then you can make the property type IEnumerable<InterfaceC> , which will work in .NET 4.0 or higher:
interface InterfaceA
{
IEnumerable<InterfaceC> D { get; }
}
class ClassE : InterfaceA
{
public IEnumerable<InterfaceC> D
{
get { return MethodThatReturnsListOfTypeClassF(); }
}
}
Otherwise, it's a purely aesthetic choice between:
new List<InterfaceC>(MethodThatReturnsListOfTypeClassF()) MethodThatReturnsListOfTypeClassF().Cast<InterfaceC>().ToList() MethodThatReturnsListOfTypeClassF().ToList<InterfaceC>()
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I haven't decided yet on the exact implementation, but it's likely to be the following:
- add items to the list or add the items directly into the database, depending on what I feel is best
- display the list on a webpage, possibly using paging depending on the number of items in that list. I have no idea at the moment whether it will be a few items or a few dozen.
What are the advantages of using a readonly collection class? I assume it's slightly faster, but otherwise I have no idea of what it implicates.
Side info:
I've only written the data access layer of my program so far. Very soon starting on user interface.
Having said that, I've already got the implementation to insert items directly into the database and have no collection class that supports inserting, deleting or modifying items in that list yet.
My fellow team members haven't started coding yet, so I can still easily change the type to IEnumerable.
I lead a team of 3 people to make a school project to make a small program for a client. My teacher told me and my team members that I should make a seperate data access layer, cause my code is too complicated for my team mates to understand, but end up making the same user interface(website). So need to have an interface so everything keeps working regardless which DAL we use. My team members have little experience with extension methods, generics and lambda expressions.
|
|
|
|
|
The main advantage of returning an IReadOnlyList<T> or IEnumerable<T> is that it makes it obvious that you can't change the list.
With your current implementation, the following code looks sensible:
InterfaceA theInstance = GetTheInstanceOfClassE();
theInstance.D.Add(new ClassF());
However, since the getter for property <c>D is returning a new List<T> every time you call it, any changes to the list will be discarded.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
As I said before, the code is a bit simplified, here is closer to the actual implementation.
private List<InterfaceType> listofitems;
public List<InterfaceType> ListOfItems
{
get {
if(listofitems==null)
{
listofitems= new List<InterfaceType>(ClassType.GetListOfTypeClassType(this.id));
}
return listofitems;
}
}
A readonly list, does it mean you can't change the list or the list AND its contents?
I think it's the latter, but I'm not sure. The list itself is pretty much already protected by not adding a setter for it.
|
|
|
|
|
If you expose it as an IReadOnlyList<T> , the caller won't be able to change the contents of the list.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
User Information I.e Profile information such as name ,dob etc filled by user during registration?
|
|
|
|
|
|
How to change Login button to logout after login in same page?
krishnendu Nandi
|
|
|
|
|
butLogin.Text = "Logout";
Then just check if he is logged in in the Click event handler and perform the appropriate action.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Hi, I am hoping someone can help me with this. I need a program that counts char,vowels and words. I can get it to do all those things alone, but I am at a loss on how to make it all work together. Please help. Thanks!
This is the program to count char, it works fine.....
#include <stdio.h>
#include <string.h>
#define MAXNUM 1000
int countchar(char[]);
int main()
{
char message [MAXNUM];
int numchar;
printf("\nType in any number of characters : ");
gets(message);
numchar = countchar(message);
printf("\nThe number of characters is %d",numchar);
return 0;
}
int countchar(char list [])
{
int i, count = 0;
for(i=0; list[i] != '\0'; i++)
count++;
return(count);
}
This is the program to count vowels, it worked fine until i tried to add the char count.....
#include<stdio.h>
int main()
{
char str, line[150];
int i,v,c,ch,d,s,o,l, countchar, count, list;
o=v=c=ch=l=d=s=0;
printf("Enter a line of string:\n");
gets(line);
for(i=0;line[i]!='\0';++i)
{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u' || line[i]=='A' || line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U')
++v;
}
{
int countchar(char list [])
int i, count = 0;
for(i=0; list[i] != '\0'; i++)
count++;
return(count);
}
printf("Vowels: %d",v);
printf("characters %d",countchar);
return 0;
}
|
|
|
|
|
And what, pray, does that have to do with C#?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Your first problem is that this is C++ code and you have posted in the C# forum.
However ...
You should create all the separate functions to perform a specific action, and return the appropriate count. You then call each one from main passing the string to it. Something like:
int main()
{
int characterCount;
int vowelCount;
int digitCount;
char message [MAXNUM];
printf("\nType in any number of characters : ");
gets(message);
characterCount = CountCharacters(message);
vowelCount = CountVowels(message);
digitCount = CountDigits(message);
return 0;
}
Then you just have to write each function to do the counting and return the total.
|
|
|
|
|
This is supposed to be c code, I used my C book as the base of the code.Thanks for the tips. Can you help me with the counting? I think the problem I am running into is that I used i once for example when counting vowels and can not use it again when counting words. I'm really stuck here.
|
|
|
|
|
I am trying what you suggested and now I get the errors countChar can not be used as a function and, invalid types of int for array. I am really lost.
|
|
|
|
|
I would suggest you go back to your C reference and work slowly through the examples. If you do not understand the basics of writing functions then you are not going to get very far. Also, when you have further questions please use the C++ forum.
|
|
|
|
|
my error
An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
Line 60: DBLaxmiTatkalEntities2 objentity1 = new DBLaxmiTatkalEntities2();
Line 61:
Line 62: objentity1.TblRootMasterDetails.AddObject(objstud1);
Line 63: objentity1.SaveChanges();
Line 64: }
my code is
public void insertdatarootmasterDetails(TblRootMasterDetail objstud1)
{
DBLaxmiTatkalEntities2 objentity1 = new DBLaxmiTatkalEntities2();
objentity1.TblRootMasterDetails.AddObject(objstud1);
objentity1.SaveChanges();
}
|
|
|
|
|
The error message is quite clear. You have two different context objects trying to load the same entity. That's not supported. Somewhere in your code you have instantiated two DBLaxmiTatkalEntities2 objects and they are both trying to load the same entity, or you have two or more different context objects trying to track the same table.
|
|
|
|
|
When in c# we add any new windows form than that form is by default inherited from the Form class so i want to see this Form class and i want to change something in that by default Form class for my project. So where is this Form class and how i can change it ?
|
|
|
|
|
You can't change the form class (or any of the framework supplied classes). What you can do is inherit from the form class and overload/override the base methods you want to change, adding the methods you need for your custom requirement.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
As Mycroft says, you cannot change the Form class, any more than you can change all Ford cars to have six wheels becasue the design information is not available to you for modification.
However, there are two ways to do what you want:
1) You can create a new MyForm class, which derives from Form and includes your code. Then use that as the base for your forms instead of the Form class and they will inherit the functionality.
2) You can change the items that are created when you create a new form or a new project by editingthe templates VS uses to create the actual files: Adding your items to Visual Studio default files[^] explains the process.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Dear All,
My Requirement = I have page on which it having more than 8 tab,I want to display multiple grid onClick of each tab,If i write code in each tab ContentTemplate, my page become to heavy,so it will take lot of time to load.
Current Way = I am using Ajax tab control in one of my project it has ContentTemplate and each ContentTemplate has one iframe, so onclick of each tab related page open in related iframe and all the grid on that page loads.
Problem Current Practice : = No of Pages increases.
Question : Can you suggest me best practice of Tab Concept,So that on each tab click,i should able to load heavy grid, so that each tab content load quickly.
My requirnment is I want to keep Tab Concept only.
Thanking You
modified 15-Apr-14 23:50pm.
|
|
|
|
|
Ask your question in the ASP.NET forum. This really doesn't have anything to do with C#.
|
|
|
|
|
Hello,
I have a window form that have two buttons , (Export & import). How i will can program each one to export all the data in one file and save them in my desktop .And import them again to the program. ??
Any one can help me with source code, I'm using phpmyadmin with C#
Thanks
|
|
|
|
|
Member 10724020 wrote: Any one can help me with source code Sorry, but this site exists to help people with the code they have written. It does not provide code to order.
|
|
|
|