|
Member 10579673 wrote: please help. With what: you have not given us any idea where your problem lies?
|
|
|
|
|
Hi,
i need to access public static member of one class into another class.
please provide the help. Learning c#.
Ex:
class ABC
{
static int nEllipsecount = 0;
// in some function increment nEllipseCount;
};
// class xyz in another file
class ABC;
class xyz
{
if(ABC :: nEllipseCount >0)
{
//Process these statements;
}
};
i couldn't be able access static value into to another class.
is my approach wrong ? Please help me to resolve.
Thanks & Regards,
Royal
|
|
|
|
|
First, as you've shown it, nEllipsecount is NOT public.
In c# the default is private.
So, what you seem to want is:
class ABC
{
public static int nEllipsecount = 0;
}
class xyz
{
if (ABC.nEllipseCount >0)
{
}
}
If it isn't made public then you can't see it from xyz at all.
(Unless it is protected and you inherit from ABC .)
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
Thanks alot Matt,
public static int nEllipsecount = 0;
In the above statement I'm declaring the static member in public only,
kindly tell me any other way i can declare as public.
Thanks & Regards,
Royal
|
|
|
|
|
You can't declare a public member/method/class etc, with anything other than the public keyword. C# requires explicit scope declaration if you're trying to do anything other than declare something as private, which is the default scope. What are you trying to achieve because using a public static is generally not a good idea?
|
|
|
|
|
Your code is hinting that you're working with C++ and not C#. Is this true??
|
|
|
|
|
Even in C++, which this is, you should not do that.
|
|
|
|
|
Can someone tell me how the moving tape/slideshow created in c# apps?It is often found on different websites, i.e. msn.arabia. Also tell the name of this feature in visual studio... Thanks
|
|
|
|
|
|
First let me pre-face, I am not looking for the LINQ answer. LINQ brings the entire document over the wire and then projects the document, which is worthless when trying to reduce network usage. Don't make me go to stack overflow!
Question:
How can I send a find query to MongoDB using the Official C# Mongo class library, and use a server-side projection? When I run
<br />
db.DBNAME.find(<br />
{_id:'401835_2014_05_01', <br />
Points: {<br />
$elemMatch: {<br />
ExtendedId:"xxxxxxx"<br />
} <br />
}<br />
},<br />
{ "Points.$":1}<br />
)<br />
from the command line (well ROBOMONGO) the world is a happy place and the projection works great. However, there seems to exist no method to call a server-side projection from the C# library????
note, I believe DB.eval can do it but db.eval is for ADMIN only and can lock the database so I am trying to avoid that option.
|
|
|
|
|
No idea if this makes any sense, but this SO answer[^] ( ) suggests that you can use the SetFields method[^] on your MongoCursor[^] to specify the server-side projection.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I will try it but I am not very optimistic. I am not attempting to restrict the fields but restrict the fields that match. For example: { "Points":1} would return the wrong document tree and the projection must be: { "Points.$":1}. The latter, unfortunately, isn't a field name.
|
|
|
|
|
Hi Guys
I would like to produce an internet cafe management system using C# and SQL, Has anyone done this before and had a successful system development?
Where would be a good starting point?
Thank You
|
|
|
|
|
Member 10920279 wrote: Has anyone done this before and had a successful system development? Yup.
Member 10920279 wrote: Where would be a good starting point? Google, keyword "kiosk mode".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Another way to do this query please
var topRatedProducts = (from product in _container.Products.Include("ProductReviews")
orderby product.ProductReviews.Average((x) => x.StarRate) descending
select product).Distinct((y) => y.ProductName);
return topRatedProducts.Take(iTopCount);
|
|
|
|
|
As you've found, the built-in Distinct extension method[^] doesn't provide an overload which compares objects by a property. You'll need to roll your own:
using System;
using System.Collections.Generic;
public static class SetExtensions
{
private static IEnumerable<TSource> DistinctByIterator<TSource, TKey>(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IEqualityComparer<TKey> keyComparer)
{
var knownKeys = new HashSet<TKey>(keyComparer);
try
{
foreach (var item in source)
{
if (knownKeys.Add(keySelector(item)))
{
yield return item;
}
}
}
finally
{
knownKeys = null;
}
}
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(
this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IEqualityComparer<TKey> keyComparer = null)
{
if (source == null) throw new ArgumentNullException("source");
if (keySelector == null) throw new ArgumentNullException("keySelector");
return DistinctByIterator(source, keySelector, keyComparer);
}
}
With that in place, you can update your query to use the new method:
var topRatedProducts = (from product in _container.Products.Include("ProductReviews")
orderby product.ProductReviews.Average((x) => x.StarRate) descending
select product).DistinctBy(y => y.ProductName);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard, I've just starting in c# and EF coding you saved my day.
|
|
|
|
|
Hi,
I am using Thought.vCards library to generate vCard contact but I am getting the following error:
Use of unassigned local variable 'vcard_writer'
Here is my code with thanks...
vCardPhone vphone1 = new vCardPhone("39753975", vCardPhoneTypes.Cellular);
vCardPhone vphone2 = new vCardPhone("17681768", vCardPhoneTypes.Work);
vCard my_vcard = new vCard();
my_vcard.Phones.Add(vphone1);
my_vcard.Phones.Add(vphone2);
vCardWriter vcard_writer;
vcard_writer.Write(my_vcard, "c:\\temp\\myvcard.vcf");
Technology News @ www.JassimRahma.com
|
|
|
|
|
You are seeing this error in your compilation stage because the compiler has identified that you haven't instantiated vcard_writer. So, use new to instantiate it.
|
|
|
|
|
I did tried that but getting:
Cannot create an instance of the abstract class or interface
Technology News @ www.JassimRahma.com
|
|
|
|
|
Look into the library to see if there's any non-abstract classes that derive from vcard_writer and instantiate it.
The best way to look for help with Third-Party products is to look into their forums.
|
|
|
|
|
This means that you need to instantiate it using a derived class. How abouts you actually read the documentation for the stuff you're trying to use and find out which classes are derived from this? I believe it even comes with examples.
|
|
|
|
|
How to write a code for opening a file and uploading its contents on to a linked list
|
|
|
|
|
Please read the forum guidelines before posting questions.
You can find them in the topmost post of each forum.
|
|
|
|
|
Actually, this is quite an interesting question. On the surface, it seems pretty straightforward, but in reality you can learn a lot from it. Let's start by examining your requirements - you want to open a file, retrieve the contents and put them into a linked list. First of all, what part of the contents do you want to put into each node of the list? Is it a line per node? A paragraph? Does the file contain text? Is it binary?
Assuming, for the sake of argument, that you want to read a text file in and store each line in a new node, how would you actually design this? Would you have a single class that did all the work? Well, I wouldn't, as that would be violating single responsibility, so you would probably want to separate out the file handling side from the linked list management side. Possibly use an event to signal to the linked list that it needs to add a new node. I hope that this helps give you some food for thought.
|
|
|
|