Search Results

Search found 50973 results on 2039 pages for 'class names'.

Page 27/2039 | < Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >

  • how to create property of type generic class?

    - by Anish
    public class SelectionList<T> : ObservableCollection<SelectionItem<T>> where T : IComparable<T> { // Code } public class SelectionItem<T> : INotifyPropertyChanged { // Code } I need to create a property which is of the type SelectionList...as follows: public SelectionList<string> Sports { get; set; }. But when I replace string with DataRowView, as public SelectionList<DataRowView> Sports { get; set; }. I am getting error. Please help

    Read the article

  • Python. Strange class attributes behavior

    - by Eugene
    >>> class Abcd: ... a = '' ... menu = ['a', 'b', 'c'] ... >>> a = Abcd() >>> b = Abcd() >>> a.a = 'a' >>> b.a = 'b' >>> a.a 'a' >>> b.a 'b' It's all correct and each object has own 'a', but... >>> a.menu.pop() 'c' >>> a.menu ['a', 'b'] >>> b.menu ['a', 'b'] How could this happen? And how to use list as class attribute?

    Read the article

  • Load class based on SDK version

    - by Bostjan
    Is there any way I can load a class based on what version of the OS the phone is running? For example: I made an app which requires 1.6+ Android. Is there a way for me to load one class or the other based on what OS the phone is running? I'm asking this specifically for contacts. The database was changed from 1.6 to 2.0 and the old version doesn't retrieve contacts on the new OS phone. I'd still like to keep my 1.6 requirement, but at the same time I'd like 2.0+ phones to access the contact part of the app. So can I make 2 APIs, somehow pack them with the app and decide on the fly which I choose to import?

    Read the article

  • Access to an "upper" instance of a class from another instance of a different class

    - by BorrajaX
    Hello everyone! I have a tricky question and probably what I want to do is not even possible but... who knows... Python seems very flexible and powerful... I'd like to know if there's a way to access to the class (or its fields) where an object is instanciated. Let's say I have: def Class1: def __init__(self): self.title = "randomTitle" self.anotherField = float() self.class2Field = Class2() and the class whose type will be the class2Field: def Class2: def __init__(self): self.field1 = "" self.field2 = "" # . . . # I'd like to know if there's a way to access the instance of Class1 from the instance of Class2 that is declared in Class1 (meaning, accessing the fields of Class1 from the variable self.class2Field in that Class1 instance) I know I can always change the init in Class2 to accept a Class1 parameter, but I'd like to know if there's another way of "climbing" through the class hierachy... Thank you very much!

    Read the article

  • Django model class and custom property

    - by dArignac
    Howdy - today a weird problem occured to me: I have a modle class in Django and added a custom property to it that shall not be saved into the database and therefore is not represent in the models structure: class Category(models.Model): groups = models.ManyToManyField(Group) title = defaultdict() Now, when I'm within the shell or writing a test and I do the following: c1 = Category.objects.create() c1.title['de'] = 'german title' print c1.title['de'] # prints "german title" c2 = Category.objects.create() print c2.title['de'] # prints "german title" <-- WTF? It seems that 'title' is kind of global. If I change title to a simple string it works as expected, so it has to do something with the dict? I also tried setting title as a property: title = property(_title) But that did not work, too. So, how can I solve this? Thank you in advance! enter code here

    Read the article

  • Basic class returns object reference instead of Array

    - by php-b-grader
    I have very basic class: class Customer { protected $id; protected $customer; public function __construct($customer_id) { $this->id = $customer_id; return $this->set_customer(); } protected function set_customer() { $query = mysql_query("SELECT * FROM customer WHERE id = '$this->id'"); $this->customer = mysql_fetch_row($query); return $this->customer; } } $customer = new Customer($order->customer->id); print_r($customer); This is not doing what I want it to but I understand why... $customer returns a reference to the Customer Object... What I want is the MySQL row array from the mysql_fetch_row() - How do I return the array? What am I missing?

    Read the article

  • Using pipes inside a class in C++

    - by Paul
    I'm trying to use this tutorial to make plots with Gnuplot in C++. However I will be using the pipe to Gnuplot from within a class, but then I run into some problems: I've got a header file where I declare all variables etc. I need to declare the pipe-variable here too, but how do I do that? I've tried doing it straight away, but it doesn't work: Logger.h: class Logger { FILE pipe; } Logger.cpp: Logger::Logger() { //Constructor *pipe = popen("gnuplot -persist","w"); } Gives the error Logger.cpp:28: error: no match for ‘operator=’ in ‘*((Logger*)this)->Logger::pipe = popen(((const char*)"gnuplot -persist"), ((const char*)"w"))’ Suggestions?

    Read the article

  • Error: cant find main class

    - by Vurb
    ok so im a newbie java dev using netbeans IDE 7.1.1 and im watching this tutorial and right off the bat i get an error in my program even after 5 retypes to make sure its exactly the same as in the video so anyways this is the error Error: Could not find or load main class javagame.JavaGame Java Result: 1 and this is the code i have written package JavaGame; import javax.swing.JFrame; public class JavaGame extends JFrame { public JavaGame(){ setTitle("java game"); setSize(500, 500); setResizable(false); setVisible(true); //setDefaultCloseOperation(); } public static void main(String[] args){ } }

    Read the article

  • is counter has certain value inside a class in python

    - by mazlor
    i am learning classes in python and when i was reading the documentation i found this example that i didn't understand : class MyClass: """A simple example class""" def __init__(self): self.data = [] i = 12345 def f(self): return 'hello world' then if we assign : x = MyClass() x.counter = 1 now if we implement while loop : while x.counter < 10: x.counter = x.counter * 2 so the value of x.counter will be : 16 while for example if we have a variable y : y = 1 while y < 1 : y = y *2 then if we look for the value of y we find it 1 so i don't know how is the value of counter became 16 . thanks

    Read the article

  • Problem about C++ class (inheritance, variables scope and functions)

    - by Luigi Giaccari
    I have a class that contains some data: class DATA Now I would to create some functions that uses those data. I can do it easily by writing member functions like DATA::usedata(); Since there are hundreds of functions, I would to keep an order in my code, so I would like to have some "categories" (not sure of the correct name) like: DATA data; data.memory.free(); data.memory.allocate(); data.file.import(); data.whatever.foo(); where memory, file and whatever are the "categories" and free, allocate and foo are the functions. I tried the inheritance way, but I got lost since I can not declare inside DATA a memory or file object, error C2079 occurs: http://msdn.microsoft.com/en-us/library/9ekhdcxs%28VS.80%29.aspx Since I am not a programmer please don't be too complicated and if you have an easier way I am all ears.

    Read the article

  • Getting all inner classes by reflection

    - by Roman
    I have the following problem. I have this pretty class and now I want to get all the classes that extend that class (inner classes ) and fill 'classList' with it. ( in an automatic way of course ) public abstract class CompoundReference { private static List<Class<? extends CompoundReference>> classList = new ArrayList<Class<? extends CompoundReference>>(); @CompoundKey(gsType = User.class, dbType = UserDetailsMappings.class) public static class CUser extends CompoundReference { } @CompoundKey(gsType = Catalog.class, dbType = CatalogDetailsMappings.class) public static class CCatalog extends CompoundReference { } @CompoundKey(gsType = Product.class, dbType = ProductDetailsMappings.class) public static class CProduct extends CompoundReference { } @CompoundKey(gsType = Category.class) public static class CCategory extends CompoundReference { } @CompoundKey(gsType = Poll.class, dbType = PollDetailsMappings.class) public static class CPoll extends CompoundReference { } // much mroe inner classes Some manual solution would be just to main such a static block , that is something that I dont want to do. static { classList.addAll(Arrays.asList(CUser.class, CCatalog.class, CProduct.class, CCategory.class, CPoll.class, CComment.class, CWebPage.class, CReview.class, CPost.class, CMessage.class, CStory.class,CPicture.class)); }

    Read the article

  • What are the differences between struct and class in C++

    - by palm3D
    This question was already asked in the context of C#/.Net. Now I'd like to learn the differences between a struct and a class in (unmanaged) C++. Please discuss the technical differences as well as reasons for choosing one or the other in OO design. I'll start with an obvious difference: If you don't specify public: or private:, members of a struct are public by default; members of a class are private by default. I'm sure there are other differences to be found in the obscure corners of the C++ specification.

    Read the article

  • Passing a class ("Country.class") as an argument in Java

    - by Coronatus
    I'm trying to make a method that takes an argument of Country.class, User.class etc, and returns argument.count(). All the possible classes that I would give to this method extend from Model and have the method count(). My code: private static long <T> countModel(Model<T> clazz) { return clazz.count(); } Called by: renderArgs.put("countryCount", countModel(Country.class)); However this just doesn't work at all. How do I do this, please?

    Read the article

  • Do Portable Class Libraries work with .net 3.5?

    - by Eric
    I am running Windows 8 and have both Visual Studio 2010 Ultimate w/sp1 and Visual Studio 2012 Ultimate and I am trying to create a Portable Class Library that supports .net 3.5 and greater. When I first try to create a PCL I get a screen like this: I noticed that .net 3.5 is not in the list so I clicked on "Install additional frameworks" and found a Targeting Pack for version 3.5. But when I download and run "dotnetfx35setup.exe" nothing happens. And when I go back into VS and try to create a new Portable Class Library, it lists the same target frameworks as before. I have also turned on the Windows Features for .NET Framework 3.5 and am now out of ideas. Here is a screen shot in case I missed something else. Thanks,

    Read the article

  • Doubt about a particular pattern of Javascript class definition

    - by fenderplayer
    Recently i saw the following code that creates a class in javascript: var Model.Foo = function(){ // private stuff var a, b; // public properties this.attr1 = ''; this.attr2 = ''; if(Model.Foo._init === 'undefined'){ Model.Foo.prototype = { func1 : function(){ //...}, func2 : function(){ //... }, //other prototype functions } } Model.Foo._init = true; } // Instantiate and use the class as follows: var foo = new Model.Foo(); foo.func1(); I guess the _init variable is used to make sure we don't define the prototypes again. Also, i feel the code is more readable since i am placing everything in a function block (so in oop-speak, all attributes and methods are in one place). Do you see any issues with the code above? Any pitfalls of using this pattern if i need to create lots of classes in a big project?

    Read the article

  • Python: Give a class its own `self` at instantiation time

    - by SuperDisk
    I've got a button class that you can instantiate like so: engine.createElement((0, 0), Button(code=print, args=("Stuff!",))) And when it is clicked it will print "Stuff!". However, I need the button to destroy itself whenever it is clicked. Something like this: engine.createElement((0, 0), Button(code=engine.killElement, args=(self,))) However, that would just kill the caller, because self refers to the caller at that moment. What I need to do is give the class its own 'self' in advance... I thought of just making the string 'self' refer to the self variable upon click, but what if I wanted to use the string 'self' in the arguments? What is the way to do this? Is my architecture all wrong or something? Thanks.

    Read the article

  • Converting C# class to JavaScript

    - by AgileMeansDoAsLittleAsPossible
    Take a look at this basic class: namespace AcmeWeb { public string FirstName { get; set; } public class Person { public Person(string firstName, string lastName) { if (String.IsNullOrEmpty(firstName)) { throw new ArgumentNullException(firstName); } this.FirstName = firstName; } } } What's the best translation of this into JavaScript? This is what I'm thinking: (function(namespace) { namespace.Person = function(firstName, lastName) { // Constructor (function() { if (!firstName) { throw "'firstName' argument cannot be null or empty"; } })(); // Private memberts var _ = { firstName: firstName }; // Public members this.firstName = function(value) { if (typeof(value) === "undefined") { return _.firstName; } else { _.firstName = value; return this; } }; }; })(AcmeWeb);

    Read the article

  • Why does this basic class not work?

    - by kalaba2003
    I could not understand why my class does no t work. Returns nothing. Is there any mistake? class User { public $first_name; public $last_name; public function full_name() { if(isset($this->first_name) && isset($this->last_name)) { return $this->first_name . " " . $this->last_name; } else { return "No name!"; } } public function assign () { $this->first_name = "Name"; $this->last_name = "Surname"; } } $user = new User(); $user->assign(); $user->full_name(); ?>

    Read the article

  • Load custom class properly

    - by LinusAn
    I have a custom class which I want to "load" inside the firstViewController and then access it from other classes by segues. My Problem is, I can't even access and change the instance variable inside the firstViewController. Somehow I'm "loading" it wrong. Here is the code I used until now: inside viewController.h @property (strong, nonatomic) myClass *newClass; inside viewController.m @synthesize newClass; I then try to access it by: self.newClass.string = @"myString"; if(newClass.string == @"myString"){ NSLog(@"didn't work"); } Well, I get "didn't work". Why is that? When I write myClass *newClass = [myClass new]; It does work. But the class and its properties gets overwritten every time the ViewController loads again. What would you recommend? Thank you very much.

    Read the article

  • How can I use UML to model a relationship between two classes, where one has functions exposed as friend to the other?

    - by user1796528
    I have a two classes: ------------ --------------- X Y ------------ --------------- relation ------------ ------------------ --------------- A() C() B() D() E() ------------ --------------- I want to inherit just these two functions from X class, where they are defined with the friend access modifier. My class will be: --------------- Y --------------- --------------- C() A() D() --------------- Y class uses some functions of X class namely A and D. How can I model this relationship in a UML class diagram?

    Read the article

  • What are the differences between abstract classes, interfaces, and when to use them

    - by user66662
    Recently I have started to wrap my head around OOP, and I am now to the point where the more I read about the differences between Abstract classes and Interfaces the more confused I become. So far, neither can be instantiated. Interfaces are more or less structural blueprints that determine the skeleton and abstracts are different by being able to partially develop code. I would like to learn more about these through my specific situation. Here is a link to my first question if you would like a little more background information: What is a good design model for my new class? Here are two classes I created: class Ad { $title; $description $price; function get_data($website){ } function validate_price(){ } } class calendar_event { $title; $description $start_date; function get_data($website){ //guts } function validate_dates(){ //guts } } So, as you can see these classes are almost identical. Not shown here, but there are other functions, like get_zip(), save_to_database() that are common across my classes. I have also added other classes Cars and Pets which have all the common methods and of course properties specific to those objects (mileage, weight, for example). Now I have violated the DRY principle and I am managing and changing the same code across multiple files. I intend on having more classes like boats, horses, or whatever. So is this where I would use an interface or abstract class? From what I understand about abstract classes I would use a super class as a template with all of the common elements built into the abstract class, and then add only the items specifically needed in future classes. For example: abstract class content { $title; $description function get_data($website){ } function common_function2() { } function common_function3() { } } class calendar_event extends content { $start_date; function validate_dates(){ } } Or would I use an interface and, because these are so similar, create a structure that each of the subclasses are forced to use for integrity reasons, and leave it up to the end developer who fleshes out that class to be responsible for each of the details of even the common functions. my thinking there is that some 'common' functions may need to be tweaked in the future for the needs of their specific class. Despite all that above, if you believe I am misunderstanding the what and why of abstracts and interfaces altogether, by all means let a valid answer to be stop thinking in this direction and suggest the proper way to move forward! Thanks!

    Read the article

  • how to pass an id number string to this class

    - by Phil
    I'm very much a vb person, but have had to use this id number class in c#. I got it from http://www.codingsanity.com/idnumber.htm : using System; using System.Text.RegularExpressions; namespace Utilities.SouthAfrica { /// <summary> /// Represents a South African Identity Number. /// valid number = 7707215230080 /// invalid test number = 1234567891234 /// /// </summary> [Serializable()] public class IdentityNumber { #region Enumerations /// <summary> /// Indicates a gender. /// </summary> public enum PersonGender { Female = 0, Male = 5 } public enum PersonCitizenship { SouthAfrican = 0, Foreign = 1 } #endregion #region Declarations static Regex _expression; Match _match; const string _IDExpression = @"(?<Year>[0-9][0-9])(?<Month>([0][1-9])|([1][0-2]))(?<Day>([0-2][0-9])|([3][0-1]))(?<Gender>[0-9])(?<Series>[0-9]{3})(?<Citizenship>[0-9])(?<Uniform>[0-9])(?<Control>[0-9])"; #endregion #region Constuctors /// <summary> /// Sets up the shared objects for ID validation. /// </summary> static IdentityNumber() { _expression = new Regex(_IDExpression, RegexOptions.Compiled | RegexOptions.Singleline); } /// <summary> /// Creates the ID number from a string. /// </summary> /// <param name="IDNumber">The string ID number.</param> public IdentityNumber(string IDNumber) { _match = _expression.Match(IDNumber.Trim()); } #endregion #region Properties /// <summary> /// Indicates the date of birth encoded in the ID Number. /// </summary> /// <exception cref="System.ArgumentException">Thrown if the ID Number is not usable.</exception> public DateTime DateOfBirth { get { if(IsUsable == false) { throw new ArgumentException("ID Number is unusable!", "IDNumber"); } int year = int.Parse(_match.Groups["Year"].Value); // NOTE: Do not optimize by moving these to static, otherwise the calculation may be incorrect // over year changes, especially century changes. int currentCentury = int.Parse(DateTime.Now.Year.ToString().Substring(0, 2) + "00"); int lastCentury = currentCentury - 100; int currentYear = int.Parse(DateTime.Now.Year.ToString().Substring(2, 2)); // If the year is after or at the current YY, then add last century to it, otherwise add // this century. // TODO: YY -> YYYY logic needs thinking about if(year > currentYear) { year += lastCentury; } else { year += currentCentury; } return new DateTime(year, int.Parse(_match.Groups["Month"].Value), int.Parse(_match.Groups["Day"].Value)); } } /// <summary> /// Indicates the gender for the ID number. /// </summary> /// <exception cref="System.ArgumentException">Thrown if the ID Number is not usable.</exception> public PersonGender Gender { get { if(IsUsable == false) { throw new ArgumentException("ID Number is unusable!", "IDNumber"); } int gender = int.Parse(_match.Groups["Gender"].Value); if(gender < (int) PersonGender.Male) { return PersonGender.Female; } else { return PersonGender.Male; } } } /// <summary> /// Indicates the citizenship for the ID number. /// </summary> /// <exception cref="System.ArgumentException">Thrown if the ID Number is not usable.</exception> public PersonCitizenship Citizenship { get { if(IsUsable == false) { throw new ArgumentException("ID Number is unusable!", "IDNumber"); } return (PersonCitizenship) Enum.Parse(typeof(PersonCitizenship), _match.Groups["Citizenship"].Value); } } /// <summary> /// Indicates if the IDNumber is usable or not. /// </summary> public bool IsUsable { get { return _match.Success; } } /// <summary> /// Indicates if the IDNumber is valid or not. /// </summary> public bool IsValid { get { if(IsUsable == true) { // Calculate total A by adding the figures in the odd positions i.e. the first, third, fifth, // seventh, ninth and eleventh digits. int a = int.Parse(_match.Value.Substring(0, 1)) + int.Parse(_match.Value.Substring(2, 1)) + int.Parse(_match.Value.Substring(4, 1)) + int.Parse(_match.Value.Substring(6, 1)) + int.Parse(_match.Value.Substring(8, 1)) + int.Parse(_match.Value.Substring(10, 1)); // Calculate total B by taking the even figures of the number as a whole number, and then // multiplying that number by 2, and then add the individual figures together. int b = int.Parse(_match.Value.Substring(1, 1) + _match.Value.Substring(3, 1) + _match.Value.Substring(5, 1) + _match.Value.Substring(7, 1) + _match.Value.Substring(9, 1) + _match.Value.Substring(11, 1)); b *= 2; string bString = b.ToString(); b = 0; for(int index = 0; index < bString.Length; index++) { b += int.Parse(bString.Substring(index, 1)); } // Calculate total C by adding total A to total B. int c = a + b; // The control-figure can now be determined by subtracting the ones in figure C from 10. string cString = c.ToString() ; cString = cString.Substring(cString.Length - 1, 1) ; int control = 0; // Where the total C is a multiple of 10, the control figure will be 0. if(cString != "0") { control = 10 - int.Parse(cString.Substring(cString.Length - 1, 1)); } if(_match.Groups["Control"].Value == control.ToString()) { return true; } } return false; } } #endregion } } Here is the code from my default.aspx.cs page: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Utilities.Southafrica; <- this is the one i added to public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { var someNumber = new IdentityNumber("123456"); <- gives error } } Can someone please tell the syntax for how I pass an id number to the class? Thanks

    Read the article

< Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >